@fairmint/ui 0.2.23 → 0.2.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38333,6 +38333,90 @@ function formatDate(dateString) {
38333
38333
  function formatPercent(n, decimals = 2) {
38334
38334
  return `${n.toFixed(decimals)}%`;
38335
38335
  }
38336
+ const COUNTRY_LOCALES = {
38337
+ US: "en-US",
38338
+ CA: "en-CA",
38339
+ GB: "en-GB",
38340
+ IE: "en-IE",
38341
+ AU: "en-AU",
38342
+ NZ: "en-NZ",
38343
+ FR: "fr-FR",
38344
+ BE: "fr-BE",
38345
+ LU: "fr-LU",
38346
+ DE: "de-DE",
38347
+ AT: "de-AT",
38348
+ CH: "de-CH",
38349
+ NL: "nl-NL",
38350
+ ES: "es-ES",
38351
+ IT: "it-IT",
38352
+ PT: "pt-PT",
38353
+ BR: "pt-BR",
38354
+ SE: "sv-SE",
38355
+ NO: "nb-NO",
38356
+ DK: "da-DK",
38357
+ FI: "fi-FI",
38358
+ PL: "pl-PL",
38359
+ JP: "ja-JP",
38360
+ CN: "zh-CN",
38361
+ IN: "en-IN",
38362
+ SG: "en-SG"
38363
+ };
38364
+ function localeForCountry(country) {
38365
+ if (!country) return "en-US";
38366
+ const key = country.toUpperCase();
38367
+ return COUNTRY_LOCALES[key] ?? "en-US";
38368
+ }
38369
+ const toNumber = (value) => {
38370
+ if (typeof value === "number") return value;
38371
+ if (value.trim() === "") return Number.NaN;
38372
+ const parsed = Number(value);
38373
+ return Number.isFinite(parsed) ? parsed : Number.NaN;
38374
+ };
38375
+ function formatMonetary(monetary, options = {}) {
38376
+ const {
38377
+ locale: explicitLocale,
38378
+ country,
38379
+ fallbackCurrency = "USD",
38380
+ compactWholeNumbers = true
38381
+ } = options;
38382
+ if (monetary === null || monetary === void 0) return "";
38383
+ let amount;
38384
+ let currency;
38385
+ if (typeof monetary === "number" || typeof monetary === "string") {
38386
+ amount = toNumber(monetary);
38387
+ currency = fallbackCurrency.toUpperCase();
38388
+ } else {
38389
+ amount = toNumber(monetary.amount);
38390
+ currency = (monetary.currency || fallbackCurrency).toUpperCase();
38391
+ }
38392
+ if (!Number.isFinite(amount)) return "";
38393
+ const locale = explicitLocale ?? localeForCountry(country);
38394
+ let nativeFractionDigits = 2;
38395
+ try {
38396
+ const resolved = new Intl.NumberFormat(locale, {
38397
+ style: "currency",
38398
+ currency
38399
+ }).resolvedOptions().maximumFractionDigits;
38400
+ if (typeof resolved === "number") nativeFractionDigits = resolved;
38401
+ } catch {
38402
+ }
38403
+ const isWhole = Number.isInteger(amount);
38404
+ const minimumFractionDigits = compactWholeNumbers && isWhole ? 0 : nativeFractionDigits;
38405
+ const subUnitThreshold = 10 ** -nativeFractionDigits;
38406
+ const subUnit = Math.abs(amount) > 0 && Math.abs(amount) < subUnitThreshold;
38407
+ const maximumFractionDigits = subUnit ? Math.max(6, nativeFractionDigits) : nativeFractionDigits;
38408
+ try {
38409
+ return new Intl.NumberFormat(locale, {
38410
+ style: "currency",
38411
+ currency,
38412
+ minimumFractionDigits,
38413
+ maximumFractionDigits
38414
+ }).format(amount);
38415
+ } catch {
38416
+ const fallbackDigits = subUnit ? maximumFractionDigits : minimumFractionDigits;
38417
+ return `${amount.toFixed(fallbackDigits)} ${currency}`;
38418
+ }
38419
+ }
38336
38420
  const TABULAR_NUMS = { fontVariantNumeric: "tabular-nums" };
38337
38421
  function Currency({ value, precise = false, currency, style, ...rest }) {
38338
38422
  let formatted;
@@ -41133,6 +41217,7 @@ export {
41133
41217
  formatCurrency,
41134
41218
  formatCurrencyPrecise,
41135
41219
  formatDate,
41220
+ formatMonetary,
41136
41221
  formatNumber,
41137
41222
  formatPercent,
41138
41223
  formatPhone,
@@ -41146,6 +41231,7 @@ export {
41146
41231
  isEthereumAddress,
41147
41232
  isRemovableWalletType,
41148
41233
  isSystemWalletType,
41234
+ localeForCountry,
41149
41235
  neutralColors,
41150
41236
  normalizePhone,
41151
41237
  normalizeWalletType,