diff --git a/.gitignore b/.gitignore index 31e1fcd..7e6db21 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -node_modules/ .idea/ +node_modules/ .DS_Store diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..2befdd2 --- /dev/null +++ b/.npmignore @@ -0,0 +1,6 @@ +.github/ +.idea/ +node_modules/ +test/ +.DS_Store +.editorconfig diff --git a/package.json b/package.json index be98b39..4241c33 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.0.0", "description": "A library to help you with family name prepositions in Dutch last names.", "main": "./src/index.js", + "types": "./src/index.d.ts", "scripts": { "test": "NODE_OPTIONS=--experimental-vm-modules jest" }, diff --git a/src/dutchPrepositions.js b/src/dutchPrepositions.js index c1d3cc4..9d6b025 100644 --- a/src/dutchPrepositions.js +++ b/src/dutchPrepositions.js @@ -5,6 +5,8 @@ // - van de // - van +// Based on https://nl.wikipedia.org/wiki/Tussenvoegsel + const DutchPrepositons = [ "aan den ", "aan der ", diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..85c813a --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,60 @@ +/** + * Searches the specified last name for a preposition. + * Optionally applies search options, if provided. + * + * @param lastName The last name to extract a preposition from. + * @param options (Optional) The options to apply to the search. + * @returns A FindPrepositionResult + */ +export function findPreposition(lastName: String, options?: FindPrepositionOptions): FindPrepositionResult; + +export interface FindPrepositionOptions { + /** + * The array of prepositions to use. Uses the default bundled list if not specified. + * When supplying your own list, make sure your prepositions end with a space when there + * is a space between the preposition and the last name, otherwise the trailing space + * would get included in the last name. + * + * Defaults to {@link DutchPrepositions}. + */ + prepositions?: String[]; + + /** + * An array of prepositions to exclude from the list. Useful if you want to exclude a specific preposition + * from the default list. Keep in mind you'll need to end most prepositions with a trailing space. + * + * Defaults to an empty array. + */ + exclude?: String[]; + + /** + * Ignores a preposition if no other characters remain after matching it. + * + * Defaults to true. + */ + ignoreIfNoSuffix?: Boolean; + + /** + * Strips the trailing space from the preposition. + * + * Defaults to false. + */ + stripTrailingSpace?: Boolean; +} + +export interface FindPrepositionResult { + /** + * The found preposition, or null if nothing was found. + */ + preposition: String | null; + + /** + * The last name without the preposition, or null if the name would be an empty string. + */ + lastName: String | null; +} + +/** + * A list of the most common Dutch prepositions, based on the Wikipedia article: https://nl.wikipedia.org/wiki/Tussenvoegsel + */ +export const DutchPrepositions: String[];