UNPKG

name-fixer

Version:

A fully typed library for fixing capitalization of people's names. Based on tamtamchik PHP library.

132 lines (130 loc) 2.81 kB
type EnvironmentOptions = { lazy?: boolean; irish?: boolean; spanish?: boolean; roman?: boolean; hebrew?: boolean; postNominal?: boolean; }; declare class Environment { private EXCEPTIONS; private REPLACEMENTS; private HEBREW; private CONJUNCTIONS; private ROMAN_REGEX; private POST_NOMINALS; private LOWER_CASE_WORDS; private postNominalsExcluded; private INITIAL_NAME_REGEX; private INITIAL_NAME_EXCEPTIONS; private options; private bckOptions; constructor(options?: EnvironmentOptions); /** * Global options setter. * * @param options */ setOptions(options?: EnvironmentOptions): void; backupOptions(): void; restoreOptions(): void; /** * Global post-nominals exclusions setter. * * @param values * @returns boolean */ excludePostNominals(values: string | string[]): void; /** * Main function for NameFixer. * * @param name * @param options * * @returns string */ nameFixer(name: string, options?: EnvironmentOptions): string; private processOptions; /** * Capitalize first letters. * * @param name * * @returns string */ private capitalizeFirstLetters; private lowercaseFinalS; /** * Define required replacements. * * @return array */ private getReplacements; /** * Update for Irish names. * * @param name * * @returns string */ private updateIrish; /** * Updates irish Mac & Mc. * * @param name * * @returns string */ private updateMac; /** * Fix roman numeral names. * * @param name * * @returns string */ private updateRoman; /** * Fix Spanish rules. * * @param name * * @returns string */ private updateSpanish; /** * Correct capitalization of initial names like JJ and TJ. * * @param name * * @return string */ private correctInitialNames; /** * Correct lower-case words of titles. * * @param name * * @return string */ private correctLowerCaseWords; /** * Fix post-nominal letter cases. * * @param name * @returns string */ private fixPostNominal; /** * Skip if string is mixed case. * * @param name * * @returns bool */ private skipMixed; } declare const setOptions: (options: EnvironmentOptions) => void; declare const excludePostNominals: (values: string | string[]) => void; declare const nameFixer: (name: string, options?: EnvironmentOptions) => string; export { Environment as default, excludePostNominals, nameFixer, setOptions };