nationid - v2.2.1
    Preparing search index...

    Interface DocumentSpec<C>

    Definition of one document type.

    Each country file under src/countries/<cc>/ exports one or more specs.

    Parametrized over the document type code so the public root getSpec<C>(code) can narrow the returned spec to the exact C the caller passed in. Existing country files annotate their specs as : DocumentSpec (no type argument), which resolves to DocumentSpec<DocumentTypeCode> via the default — no per-country changes required.

    interface DocumentSpec<C extends DocumentTypeCode = DocumentTypeCode> {
        code: C;
        confidence: Confidence;
        country: CountryCode;
        formattedRegex?: RegExp;
        hasCheckDigit: boolean;
        labelKey: string;
        mask: string;
        rawRegex: RegExp;
        scope: DocumentScope;
        format(input: string): string;
        normalize(input: string): string;
        parse(input: string): ParseResult<C>;
        validate(input: string): boolean;
    }

    Type Parameters

    Index
    code: C
    confidence: Confidence
    country: CountryCode
    formattedRegex?: RegExp

    Optional regex matching the formatted form a user might paste.

    hasCheckDigit: boolean

    True iff the spec includes a check-digit algorithm we trust to enforce.

    labelKey: string

    i18n key path, e.g. documents.SV_DUI.label. UI consumers resolve to localized text.

    mask: string

    Mask pattern (cleave-style: 0=digit, A=uppercase letter, *=alphanumeric).

    rawRegex: RegExp

    Regex matching the normalized form (no separators, uppercase).

    • Reverse of normalize, applies the canonical mask. Returns input unchanged if invalid.

      Parameters

      • input: string

      Returns string

    • Strip separators, uppercase, trim. Idempotent.

      Parameters

      • input: string

      Returns string

    • Returns true iff input passes regex AND (when applicable) check digit.

      Parameters

      • input: string

      Returns boolean