UNPKG

@frak-labs/core-sdk

Version:

Core SDK of the Frak wallet, low level library to interact directly with the frak ecosystem.

1 lines 3.25 kB
{"version":3,"file":"getCurrencyAmountKey-oIVOsRrF.cjs","names":[],"sources":["../src/constants/locales.ts","../src/utils/format/getSupportedCurrency.ts","../src/utils/format/getSupportedLocale.ts","../src/utils/format/formatAmount.ts","../src/utils/format/getCurrencyAmountKey.ts"],"sourcesContent":["/**\n * The keys for each locales\n * @inline\n */\nexport type LocalesKey = keyof typeof locales;\n\n/**\n * Map the currency to the locale\n */\nexport const locales = {\n eur: \"fr-FR\",\n usd: \"en-US\",\n gbp: \"en-GB\",\n} as const;\n","import { locales } from \"../../constants/locales\";\nimport type { Currency } from \"../../types\";\n\n/**\n * Get the supported currency for a given currency\n * @param currency - The currency to use\n * @returns The supported currency\n */\nexport function getSupportedCurrency(currency?: Currency): Currency {\n if (!currency) {\n return \"eur\";\n }\n return currency in locales ? currency : \"eur\";\n}\n","import { type LocalesKey, locales } from \"../../constants/locales\";\nimport type { Currency } from \"../../types\";\n\n/**\n * Get the supported locale for a given currency\n * @param currency - The currency to use\n * @returns The supported locale\n */\nexport function getSupportedLocale(\n currency?: Currency\n): (typeof locales)[LocalesKey] {\n if (!currency) {\n return locales.eur;\n }\n return locales[currency] ?? locales.eur;\n}\n","import type { Currency } from \"../../types\";\nimport { getSupportedCurrency } from \"./getSupportedCurrency\";\nimport { getSupportedLocale } from \"./getSupportedLocale\";\n\n/**\n * Format a numeric amount as a localized currency string\n * @param amount - The raw numeric amount to format\n * @param currency - Optional currency config; defaults to EUR/fr-FR when omitted\n * @returns Localized currency string (e.g. \"1 500 €\", \"$1,500\")\n */\nexport function formatAmount(amount: number, currency?: Currency) {\n // Get the supported locale (e.g. \"fr-FR\")\n const supportedLocale = getSupportedLocale(currency);\n\n // Get the supported currency (e.g. \"eur\")\n const supportedCurrency = getSupportedCurrency(currency);\n\n return amount.toLocaleString(supportedLocale, {\n style: \"currency\",\n currency: supportedCurrency,\n minimumFractionDigits: 0,\n maximumFractionDigits: 2,\n });\n}\n","import type { Currency, TokenAmountType } from \"../../types\";\n\n/**\n * Get the currency amount key for a given currency\n * @param currency - The currency to use\n * @returns The currency amount key\n */\nexport function getCurrencyAmountKey(\n currency?: Currency\n): keyof TokenAmountType {\n if (!currency) {\n return \"eurAmount\";\n }\n return `${currency}Amount` as keyof TokenAmountType;\n}\n"],"mappings":"AASA,MAAa,EAAU,CACnB,IAAK,QACL,IAAK,QACL,IAAK,OACT,ECLA,SAAgB,EAAqB,EAA+B,CAIhE,OAHK,GAGE,KAAY,EAAU,EAAW,KAC5C,CCLA,SAAgB,EACZ,EAC4B,CAI5B,OAHK,EAGE,EAAQ,IAAa,EAAQ,IAFzB,EAAQ,GAGvB,CCLA,SAAgB,EAAa,EAAgB,EAAqB,CAE9D,IAAM,EAAkB,EAAmB,CAAQ,EAG7C,EAAoB,EAAqB,CAAQ,EAEvD,OAAO,EAAO,eAAe,EAAiB,CAC1C,MAAO,WACP,SAAU,EACV,sBAAuB,EACvB,sBAAuB,CAC3B,CAAC,CACL,CChBA,SAAgB,EACZ,EACqB,CAIrB,OAHK,EAGE,GAAG,EAAS,QAFR,WAGf"}