import { validateNationalId } from 'idnumbers';
const result = validateNationalId('TWN', 'A123456789');
result.isValid; // true
result.extractedInfo?.location; // 'A'
// Aliases resolve to the alpha-3 code; a failure carries a machine-readable reason.
const invalid = validateNationalId('TW', 'A12345');
invalid.countryCode; // 'TWN'
invalid.reason; // 'invalid_length'
Validate a national ID number for a specific country.
Delegates to the registry-based validator lookup. Aliases (e.g. "FR", "fr") are resolved to their primary alpha-3 key (e.g. "FRA") which is returned as the countryCode in the result. For a built-in country code,
extractedInfohas that country's parse result type (#123). A country code that isn't a registered string, including a non-string from untyped JavaScript, yieldsunsupported_countryand echoes the code as passed. When a validator or parser throws, the result isvalidation_failedwith the error message, andcountryCodeis the resolved alpha-3 key (#301).