declare const _KennitalaPerson__Brand: unique symbol; /** A valid 10-digit Kennitala string for a person */ export type KennitalaPerson = string & { [_KennitalaPerson__Brand]: true; }; declare const _KennitalaCompany__Brand: unique symbol; /** A valid 10-digit Kennitala string for a person */ export type KennitalaCompany = string & { [_KennitalaCompany__Brand]: true; }; /** A valid 10-digit Kennitala string */ export type Kennitala = KennitalaPerson | KennitalaCompany; declare const _KennitalaTemporary__Brand: unique symbol; /** A valid 10-digit Kennitala string for a person with a temporary "Kerfiskennitala" */ export type KennitalaTemporary = KennitalaPerson & { [_KennitalaTemporary__Brand]: true; }; export type KennitalaType = 'person' | 'company'; /** * Trims the string and then only removes spaces and/or a dash (or en-dash) * before the last four of the ten digits. * * Defaults to returning the (trimmed) original string, if the pattern * doesn't match. * * Cleaned: * * `' 123456-7890'` ==> `'1234567890'` * * `'123456 7890 '` ==> `'1234567890'` * * `' 123456 - 7890'` ==> `'1234567890'` * * `'123456 -7890'` ==> `'1234567890'` * * Only trimmed: * * `' abc '` ==> `'abc'` * * `' 123456 - 7890'` ==> `'123456 - 7890'` * * `'kt. 123456-7890'` ==> `'kt. 123456-7890'` * * `' 1234-567890'` ==> `'1234-567890'` * * `'123 456-7890'` ==> `'123 456-7890'` */ export declare const cleanKennitalaCareful: (value: string) => string; /** * Aggressively strips away all spaces and dashes (or en-dashes) from the string, * as well as any trailing and leading non-digit gunk. * * Returns whatever is left. * * Examples: * * `' abc '` ==> `''` * * `'(kt. 123456-7890)'` ==> `'1234567890'` * * `'(kt. 123456-7890, s. 765 4321) '` ==> `'1234567890,s.7654321'` * * `'(tel. 123-4567, 765-4321)'` ==> `'1234567,7654321'` * * `'(s. 765 4321) '` ==> `'7654321'` * * `' 12 34 56 - 78 90'` ==> `'1234567890'` * * `'1-2-3 4-5 6-7-8 9-0'` ==> `'1234567890'` */ export declare const cleanKennitalaAggressive: (value: string) => string; /** * Runs minimal cleanup on the input string and if it looks like a kennitala * then then inserts a nice separator (default `'-'`) before the last four * digits. * * Defaults to returning the input untouched. */ export declare const formatKennitala: (value: string, separator?: string) => string; /** * Returns the (UTC) birth-date (or founding-date) of a "kennitala-shaped" string * ...without checking if it is a valid kennitala. * * It returns `undefined` for malformed (non-kennitala shaped) strings, * temporary "kerfiskennitalas" and kennitalas with nonsensical dates, even if * they're numerically valid. */ export declare const getKennitalaBirthDate: (value: string) => Date | undefined; type KennitalaParsingOptions = { /** * If the valdation should specifically check for a * private person, or a legal entity ("company") kennitala. * * Defaults to accepting both types. */ type?: KtType; /** * Set this flag to `true` if the parser should accept known * "Gervimaður" kennitalas (commonly used for mocking or systems-testing). * * Defaults to `false`. */ robot?: PossiblyRobot; /** * Set this flag to `true` to reject short-term temporary kennitalas * ("kerfiskennitala") given to short-stay (or no-stay) individuals/workers. * * Defaults to `false` * * BTW, Rationale for the "on by default" behavior: * - These are kennitalas of actual people, not some fake "Gervimaður". * - "Kerfiskennitalas" are, by definition, perfectly **valid** kennitalas. * - This is a simple helper library, whose purpose is only to catch obvious * mistakes and show error messages fast. * - Any real stakes filtering (including for age) should/must occur * in the next step anyway. */ rejectTemporary?: boolean; /** * `"aggressive"` mode strips away all spaces and dashes and throws away any * leading/trailing gunk. * * `false`/`"none"` performs no cleanup whatsoever, not even trimming. * * Default is `"careful"` mode, which performs only minimal cleaning on the * incoming string ...trimming it and then removing a space and/or dash * right before the last four of the ten digits. */ clean?: 'aggressive' | 'careful' | 'none' | false; /** * Set this flag to `true` to opt into a slower, more perfect * check for valid dates in permanent (non-"Kerfiskennitala") kennitalas. * * Defaults to `false` — which may result in the occational false-positive * on values starting with something impossible like "3102" (Feb. 31st) */ strictDate?: boolean; }; export type KennitalaDataPerson = { /** The plain, cleaned-up 10 digit kennitala string */ value: KennitalaPerson; /** The type of kennitala */ type: 'person'; /** Indicates if the kennitala is a "Gervimaður" — i.e. a fake/testing kennitala */ robot: PossiblyRobot extends false ? false : boolean; /** Indicates if the kennitala is a temporary "Kerfiskennitala" */ temporary?: true; /** Pretty-formatted version of the kennitala with a dash before the last four digits */ formatted: string; toString(): string; }; export type KennitalaDataCompany = { /** The plain, cleaned-up 10 digit kennitala string */ value: KennitalaCompany; /** The type of kennitala */ type: 'company'; /** Indicates if the kennitala is a "Gervimaður" — i.e. a fake/testing kennitala */ robot: false; /** Indicates if the kennitala is a temporary "Kerfiskennitala" */ temporary?: never; /** Pretty-formatted version of the kennitala with a dash before the last four digits */ formatted: string; toString(): string; }; export type KennitalaData = (KennitalaDataPerson | KennitalaDataCompany) & { type: KtType; }; /** * Parses a string value to see if may be a technically valid kennitala, * and if so, it returns a data object with the cleaned up value * along with some meta-data and pretty-formatted version. * * If the parsing/validation fails, it simply returns `undefined` */ export declare function parseKennitala(value: '', opt?: KennitalaParsingOptions): undefined; export declare function parseKennitala(kt: KennitalaCompany, opt?: KennitalaParsingOptions<'company'>): KennitalaDataCompany; export declare function parseKennitala(kt: KennitalaPerson, opt?: KennitalaParsingOptions<'person', PossiblyRobot>): PossiblyRobot extends false ? undefined | KennitalaDataPerson : KennitalaDataPerson; export declare function parseKennitala(value: string, opts?: KennitalaParsingOptions): KennitalaData | undefined; /** * Runs the input through `parseKennitala` and returns `true` if the parsing * was successful. * * Options are the same as for `parseKennitala` except that `clean` option * defaults to `"none"`. */ export declare function isValidKennitala(value: '', opts: KennitalaParsingOptions): false; export declare function isValidKennitala(value: string, opts: KennitalaParsingOptions & { type: 'person'; clean?: 'none' | false; }): value is KennitalaPerson; export declare function isValidKennitala(value: string, opts: KennitalaParsingOptions & { type: 'company'; clean?: 'none' | false; }): value is KennitalaCompany; export declare function isValidKennitala(value: string, opts?: KennitalaParsingOptions & { clean?: 'none' | false; }): value is Kennitala; export declare function isValidKennitala(value: string, opts?: KennitalaParsingOptions): boolean; /** * Detects if an input `Kennitala` is `KennitalaPerson`. * * Assumes that the input `kt` is already validated as `Kennitala` * and performs no internal validation, and is thus insanely fast, but * unreliable for random strings. * * To safely check the type of a plain, non-validated `string` input, * use `parseKennitala` and check the `.type` of the retured data object. * * That way you can also get a cleaned-up version of the kennitala. * * Example: * * ```js * const isPerson = parseKennitala(someString)?.type === 'person'; * ``` * ...or... * ```js * const isPerson = !!parseKennitala(someString, { type: 'person' }); * ``` */ export declare const isPersonKennitala: (kennitala: Kennitala) => kennitala is KennitalaPerson; /** * Detects if an input `Kennitala` is `KennitalaCompany`. * * Assumes that the input `kt` is already validated as `Kennitala` * and performs no internal validation, and is thus insanely fast, but * unreliable for random strings. * * To safely check the type of a plain, non-validated `string` input, * use `parseKennitala` and check the `.type` of the retured data object. * * That way you can also get a cleaned-up version of the kennitala. * * Example: * * ```js * const isCompany = parseKennitala(someString)?.type === 'company'; * ``` * ...or... * ```js * const isCompany = !!parseKennitala(someString, { type: 'company' }); * ``` */ export declare const isCompanyKennitala: (kennitala: Kennitala) => kennitala is KennitalaCompany; /** * Detects if an input `Kennitala` is a (temporary) "kerfiskennitala" * (a subset of valid `KennitalaPerson`s). * * Assumes that the input `kt` is already validated as `Kennitala` * and performs no internal validation, and is thus insanely fast, but * unreliable for random strings. * * To safely check the type of a plain, non-validated `string` input, * use `parseKennitala` and check the `.temporary` status of the * retured data object. * * That way you can also get a cleaned-up version of the kennitala. * * Example: * * ```js * const isTemp = !!parseKennitala(someString)?.temporary; * ``` */ export declare const isTempKennitala: (kennitala: Kennitala) => kennitala is KennitalaTemporary; type GeneratePersonOptions = { type?: 'person'; birthDate?: Date; robot?: boolean; temporary?: boolean; }; type GenerateCompanyOptions = { type: 'company'; birthDate?: Date; robot?: false; temporary?: false; }; /** * Generates a technically valid Kennitala. (Possibly a real one!) * * Defaults to making a KennitalaPerson, unless `opts.type` is set to `"company"`. * * Picks a birth date at random, unless a valid `opts.birthDate` is provided. */ export declare function generateKennitala(opts: GenerateCompanyOptions): KennitalaCompany; export declare function generateKennitala(opts: GeneratePersonOptions & { temporary: true; }): KennitalaTemporary; export declare function generateKennitala(opts?: GeneratePersonOptions): KennitalaPerson; export declare function generateKennitala(opts?: GeneratePersonOptions | GenerateCompanyOptions): Kennitala; export {};