idnumbers
    Preparing search index...

    Function defineCountry

    • Build the frozen CountryDefinition for a country module.

      source is a class with static methods, a plain object bundling module-level functions, or a CountryValidator built by createValidator or createCompositeValidator. A module's methods are wrapped so they can be called detached from their class; a built validator is used as-is (#183).

      The definition, its aliases, and its validator are frozen, so a definition cannot swap the functions the registry calls. The validator's METADATA is the module's own object and stays mutable; getCountryIdFormat() returns a copy of it.

      Type Parameters

      • K extends string
      • const A extends readonly string[]
      • M extends CountryModule<object>

      Parameters

      • key: K
      • aliases: A
      • source: M

      Returns CountryDefinition<K, A, ModuleParseResult<M>>

      import { defineCountry } from 'idnumbers/core';
      import { NationalID } from 'idnumbers/countries/twn';

      const definition = defineCountry('TWN', ['TW'], NationalID);
      definition.key; // 'TWN'
      definition.aliases; // ['TW']
      definition.validator.validate('A123456789'); // true