{"version":3,"file":"intl-data.min.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":["localeCache","currencyCache","getCurrency","currencyCode","locale","Intl","NumberFormat","resolvedOptions","undefined","commonOptions","style","currency","textWithNumbers","toLocaleString","currencyDisplay","replace","includes","Error","lengthWithNumbers","length","textWithoutNumbers","decimalPlaces","symbol","trim","formattedCurrency","formattedNumber","minimumFractionDigits","rxSymbol","RegExp","rxNumber","name","code","getLocale","localeCode","supportedLocalesOf","localeMatcher","digitGroupSeparator","decimalCharacter","currencySymbolPlacement","percentString","percentSymbolPlacement","percentSymbol"],"mappings":"AAiCA,MAAMA,EAA0C,GAC1CC,EAAoE,YAW1DC,EACdC,EACAC,GAAS,IAAIC,KAAKC,cAAeC,kBAAkBH,QAEnD,GAA4B,iBAAjBD,EACT,OAAwB,OAAjBA,EAAwB,UAAOK,EAGxC,MAAMC,EAAgB,CAAEC,MAAO,WAAYC,SAAUR,GAIrD,GAHAF,EAAcE,GAAgBF,EAAcE,IAAiB,QAGjBK,IAAxCP,EAAcE,GAAcC,GAAuB,CACrD,MAAMQ,GAAkB,GAAIC,eAAeT,EAAQ,IAAKK,EAAeK,gBAAiB,WAAYC,QAA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