{"version":3,"sources":["../src/metadata.ts"],"sourcesContent":["export interface TypePattern {\n  nationalNumberPattern: string;\n  possibleLengths: number[];\n}\n\nexport interface FormatRule {\n  // Full-match regex with capture groups, e.g. \"(\\d{3})(\\d{4})\".\n  pattern: string;\n  // Template using $1/$2/... for the capture groups, e.g. \"$1 $2\".\n  format: string;\n  // How the national prefix combines with the first group in NATIONAL\n  // format specifically, e.g. \"$NP$FG\" ($NP = nationalPrefix, $FG = the\n  // raw first group) - omitted means NATIONAL format has no prefix at all.\n  // Never applies to INTERNATIONAL format.\n  nationalPrefixFormattingRule?: string;\n  // Overrides `format` for INTERNATIONAL style specifically. The literal\n  // value \"NA\" means this rule should be skipped entirely for\n  // INTERNATIONAL (try the next matching rule) - e.g. local-only formats\n  // that omit the area code aren't valid once you need to dial\n  // internationally. Omitted (not \"NA\") means reuse `format` as-is.\n  intlFormat?: string;\n  // Upstream declaration order, least to most specific - each is a\n  // stricter refinement of the one before it, not an independent\n  // alternative. Only used by asYouType() to pick a candidate rule before\n  // enough digits exist for `pattern` to fully match; `format()` doesn't\n  // need this since it only ever formats complete numbers.\n  leadingDigits?: string[];\n}\n\nexport interface CountryMetadata {\n  // ISO 3166-1 alpha-2, e.g. \"US\". Kept on the value itself (not just as\n  // the object key) because callers group entries by calling code - once\n  // grouped, the original object key is gone.\n  region: string;\n  callingCode: string;\n  // General/fallback pattern - used directly when a type-specific match\n  // isn't available (e.g. a region without per-type data yet).\n  nationalNumberPattern: string;\n  possibleLengths: number[];\n  // Per-type patterns, each optional since not every region's upstream\n  // data distinguishes all of these (e.g. many small territories have no\n  // separate pager/uan/voicemail block at all).\n  types?: {\n    MOBILE?: TypePattern;\n    FIXED?: TypePattern;\n    TOLL_FREE?: TypePattern;\n    PREMIUM_RATE?: TypePattern;\n    SHARED_COST?: TypePattern;\n    PERSONAL_NUMBER?: TypePattern;\n    VOIP?: TypePattern;\n    PAGER?: TypePattern;\n    UAN?: TypePattern;\n    VOICEMAIL?: TypePattern;\n  };\n  // e.g. \"0\" for GB, \"1\" for NANP. Absent for regions with no national\n  // dialing prefix.\n  nationalPrefix?: string;\n  // In upstream declaration order - first full match against the national\n  // number wins, same resolution order as Google's own algorithm.\n  formats?: FormatRule[];\n}\n\nexport interface Metadata {\n  // Keyed by region, not calling code: a calling code can map to several\n  // regions (e.g. NANP's \"1\" covers US, Canada, and ~19 Caribbean\n  // territories), so calling code can't be a unique key.\n  [region: string]: CountryMetadata;\n}\n\n// Global state for injected metadata, initialized empty\nlet _metadata: Metadata = {};\n\nexport const setup = (config: { metadata: Metadata }) => {\n  _metadata = config.metadata;\n};\n\nexport const getMetadata = (): Metadata => _metadata;\n\n// These three all read whatever's currently injected via setup() - not\n// the full set of countries DialSense ships in data/, which this module\n// has no knowledge of at runtime. A country is only \"supported\" once its\n// metadata has actually been passed to setup().\nexport const getCountries = (): string[] => Object.keys(_metadata);\n\nexport const getCountryCallingCode = (country: string): number | undefined => {\n  const region = _metadata[country];\n  return region ? Number(region.callingCode) : undefined;\n};\n\nexport const isSupportedCountry = (country: string): boolean => country in _metadata;"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsEA,IAAI,YAAsB,CAAC;AAEpB,IAAM,QAAQ,CAAC,WAAmC;AACvD,cAAY,OAAO;AACrB;AAEO,IAAM,cAAc,MAAgB;AAMpC,IAAM,eAAe,MAAgB,OAAO,KAAK,SAAS;AAE1D,IAAM,wBAAwB,CAAC,YAAwC;AAC5E,QAAM,SAAS,UAAU,OAAO;AAChC,SAAO,SAAS,OAAO,OAAO,WAAW,IAAI;AAC/C;AAEO,IAAM,qBAAqB,CAAC,YAA6B,WAAW;","names":[]}