idnumbers
    Preparing search index...

    Function parseIdInfo

    • Parse information from a valid national ID number.

      Returns { ok: true, info } with what the country's parser extracted, or { ok: false, reason } saying why nothing was parsed (#123):

      • UNSUPPORTED_COUNTRY: the country code is not registered;
      • INVALID_LENGTH / INVALID_FORMAT / CHECKSUM_MISMATCH / VALIDATION_FAILED: the ID is invalid, with the same reason validateNationalId() reports;
      • NOT_PARSABLE: the ID is valid, but the country has no parser or its parser extracted nothing.

      Aliases resolve like validateNationalId(), and countryCode in the result is the resolved alpha-3 code, also when a validator or parser throws (#301). For a built-in country code, info has that country's parse result type; see ParseResultMap. A non-string country code, from untyped JavaScript, is unsupported too.

      Type Parameters

      • C extends string

      Parameters

      • countryCode: C
      • idNumber: string

      Returns ParseIdInfoResult<ParsedInfoFor<C>>

      import { parseIdInfo } from 'idnumbers';

      const result = parseIdInfo('TWN', 'A123456789');
      if (result.ok) {
      result.info.location; // 'A'
      result.info.gender; // 'male'
      } else {
      result.reason;
      }

      parseIdInfo('XX', '1').ok; // false, with reason 'unsupported_country'