Write an ID in its country's display format (#128), e.g.
formatId('BRA', '11144477735') returns '111.444.777-35'.
The ID is first normalized (see normalizeId()), so formatted, partly formatted,
and lowercase input all work; ASCII letters are uppercased and other letters stay as written. The mask is chosen by the compact length; an ID
written without separators, like 'FRA''s, is returned in its compact form.
Formatting checks only the length, not the characters, and doesn't validate. When
validateNationalId() accepts an ID, it also accepts formatId()'s output for it.
Returns null when the ID can't be laid out: an unsupported country code (a non-string
one from untyped JavaScript included), a
non-string ID, or a compact length that matches none of the country's masks (or,
for a country registered without masks, lies outside its minLength–maxLength).
Parameters
countryCode: FormatCountryCode
idNumber: string
Returns string|null
Example
import { formatId } from'idnumbers';
formatId('BRA', '11144477735'); // '111.444.777-35' formatId('BRA', '123'); // null, no mask fits this length
Write an ID in its country's display format (#128), e.g.
formatId('BRA', '11144477735')returns'111.444.777-35'.The ID is first normalized (see
normalizeId()), so formatted, partly formatted, and lowercase input all work; ASCII letters are uppercased and other letters stay as written. The mask is chosen by the compact length; an ID written without separators, like'FRA''s, is returned in its compact form. Formatting checks only the length, not the characters, and doesn't validate. WhenvalidateNationalId()accepts an ID, it also acceptsformatId()'s output for it.Returns null when the ID can't be laid out: an unsupported country code (a non-string one from untyped JavaScript included), a non-string ID, or a compact length that matches none of the country's masks (or, for a country registered without masks, lies outside its
minLength–maxLength).