createPrefixPhoneMetadata
projects/forms/input/phone-metadata.ts
Description#
Builds a CngxPhoneMetadata adapter from a region keyed prefix map, so a consumer declares the prefixes that matter instead of hand-writing the region branch and the matching closure.
The adapter resolves the line type by longest matching prefix: the matcher
with the most matched leading digits wins, so a specific '0820' fixed-line
rule beats a broader '08' mobile rule. Ties resolve to mobile (it is the
decisive case auto mask alternation cares about). An unknown region or no
matching prefix returns 'unknown', keeping the length-based fallback.
It still ships no numbering data - the caller supplies every prefix - so it is
sugar over an inline adapter, not a replacement for a real metadata library
like libphonenumber-js.
providePhoneMetadata(
createPrefixPhoneMetadata({
DE: { mobile: [/^1[567]/] },
AT: { mobile: ['650', '660', '664', '676', '699'] },
}),
);