{"version":3,"file":"intl-data.mjs","sources":["../../src/intl-data.ts"],"sourcesContent":["/** ignore */\ntype LocaleCode = string;\n/** ignore */\ntype CurrencyCode = string;\n\n/** Information about locale. */\nexport interface Locale {\n  /** BCP 47 language tag of the locale. This is simply string provided to get locale. Example: `tr-TR` */\n  code: LocaleCode;\n  /** Character to separate decimal (fraction) parts of the number from integer parts. */\n  decimalCharacter: string;\n  /** Grouping separators for integer parts, such as thousands separators or thousand/lakh/crore separators. */\n  digitGroupSeparator: string;\n  /** Place of currency symbol: `p` for prefix such as `$1.95`, or `s` for suffix such as `1.95$` */\n  currencySymbolPlacement: \"p\" | \"s\";\n  /** Place of percent symbol: `p` for prefix such as `%12`, or `s` for suffix such as `12%` */\n  percentSymbolPlacement: \"p\" | \"s\";\n  /** Percent symbol. Some locales contains spcae for percent symbol such as `12 %`, and some not `12%`. This is used to differenciate them. */\n  percentSymbol: string;\n}\n\n/** Information about currency */\nexport interface Currency {\n  /** Name of the currency. */\n  name: string;\n  /**  ISO 4217 currency codes */\n  code: CurrencyCode;\n  /** Number of digits used in decimal (fractional) part of the currency. */\n  decimalPlaces: number;\n  /** Currency symbol such as `₺`, `$`, `€` */\n  symbol: string;\n}\n\nconst localeCache: Record<LocaleCode, Locale> = {};\nconst currencyCache: Record<CurrencyCode, Record<LocaleCode, Currency>> = {};\n\nexport function getCurrency<T extends null | undefined>(currencyCode: T, locale?: string): T;\nexport function getCurrency(currencyCode: string | null | undefined, locale?: string): Currency | null | undefined;\n/**\n * Returns currency details for given currency and optionally locale. Throws error for unknown currency codes.\n *\n * @param currencyCode is the currency to use in currency formatting. Possible values are the ISO 4217 currency codes, such as \"USD\" for the US dollar.\n * @param locale is the optional string with a BCP 47 language tag. If provided returned object contains currency name in given locale.\n * @returns currency details for requested currency. Also returns `null` for `null` input and `undefined` for `undefined` input.\n */\nexport function getCurrency(\n  currencyCode: string | null | undefined,\n  locale = new Intl.NumberFormat().resolvedOptions().locale\n): Currency | null | undefined {\n  if (typeof currencyCode !== \"string\") {\n    return currencyCode === null ? null : undefined;\n  }\n\n  const commonOptions = { style: \"currency\", currency: currencyCode };\n  currencyCache[currencyCode] = currencyCache[currencyCode] || {};\n\n  // Compute currency data\n  if (currencyCache[currencyCode][locale] === undefined) {\n    const textWithNumbers = (0).toLocaleString(locale, { ...commonOptions, currencyDisplay: \"symbol\" }).replace(/[.,]/, \"\"); // \"OMR 0000\" or \"$000\" or \"RWF 0\" or \"0000 OMR\"... without decimal separator\n    // eslint-disable-next-line no-irregular-whitespace\n    if ((0).toLocaleString(locale, { ...commonOptions, currencyDisplay: \"name\" }).includes(currencyCode)) {\n      throw new Error(`Invalid currency code: ${currencyCode}.`);\n    }\n    const lengthWithNumbers = textWithNumbers.length;\n    const textWithoutNumbers = textWithNumbers.replace(/0/g, \"\");\n    const decimalPlaces = lengthWithNumbers - textWithoutNumbers.length - 1;\n    const symbol = textWithoutNumbers.trim();\n    const formattedCurrency = (0).toLocaleString(locale, { ...commonOptions, currencyDisplay: \"name\" });\n    const formattedNumber = (0).toLocaleString(locale, { minimumFractionDigits: decimalPlaces });\n    const rxSymbol = new RegExp(` ?${symbol} ?`);\n    const rxNumber = new RegExp(` ?${formattedNumber} ?`);\n    const name = formattedCurrency.replace(rxSymbol, \"\").replace(rxNumber, \"\");\n    currencyCache[currencyCode][locale] = { name, code: currencyCode, symbol, decimalPlaces };\n  }\n\n  return currencyCache[currencyCode][locale];\n}\n\nexport function getLocale(localeCode: string): Locale;\nexport function getLocale<T extends null | undefined>(localeCode: T): T;\nexport function getLocale(localeCode: string | null | undefined): Locale | undefined | null;\n/**\n * Returns locale details for given locale. Throws error for unsupported locales.\n *\n * @param localeCode is the string with a BCP 47 language tag. If provided returned object contains currency name in given locale.\n * @returns locale data for requested locale. Also returns `null` for `null` input and `undefined` for `undefined` input.\n */\nexport function getLocale(localeCode: string | null | undefined): Locale | undefined | null {\n  if (typeof localeCode !== \"string\") {\n    return localeCode === null ? null : undefined;\n  }\n\n  if (Intl.NumberFormat.supportedLocalesOf(localeCode, { localeMatcher: \"lookup\" }).length === 0) {\n    throw new Error(`Unsupported locale: ${localeCode}.`);\n  }\n\n  if (localeCache[localeCode] === undefined) {\n    const [digitGroupSeparator, decimalCharacter] = (11111.1).toLocaleString(localeCode).replace(/1/g, \"\");\n    const currencySymbolPlacement = (1).toLocaleString(localeCode, { style: \"currency\", currency: \"USD\" })[0] === \"1\" ? \"s\" : \"p\";\n    const percentString = (0.01).toLocaleString(localeCode, { style: \"percent\" });\n    const percentSymbolPlacement = percentString[0] === \"1\" ? \"s\" : \"p\";\n    const percentSymbol = percentString.replace(\"1\", \"\"); // Some locales contains space, some not.\n    localeCache[localeCode] = {\n      code: localeCode,\n      digitGroupSeparator,\n      decimalCharacter,\n      currencySymbolPlacement,\n      percentSymbolPlacement,\n      percentSymbol,\n    };\n  }\n  return localeCache[localeCode];\n}\n"],"names":[],"mappings":"AAiCA,MAAM,WAAW,GAA+B,EAAE,CAAC;AACnD,MAAM,aAAa,GAAuD,EAAE,CAAC;AAI7E;;;;;;;SAOgB,WAAW,CACzB,YAAuC,EACvC,MAAM,GAAG,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC,eAAe,EAAE,CAAC,MAAM;IAEzD,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;QACpC,OAAO,YAAY,KAAK,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC;KACjD;IAED,MAAM,aAAa,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;IACpE,aAAa,CAAC,YAAY,CAAC,GAAG,aAAa,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;;IAGhE,IAAI,aAAa,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,KAAK,SAAS,EAAE;QACrD,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,cAAc,CAAC,MAAM,EAAE,EAAE,GAAG,aAAa,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,CAAC,O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