@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.
- package/dist/fairmint-ui.cjs +86 -0
- package/dist/fairmint-ui.cjs.map +1 -1
- package/dist/fairmint-ui.js +86 -0
- package/dist/fairmint-ui.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/utils/format.d.ts +85 -0
- package/dist/utils/format.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/fairmint-ui.cjs
CHANGED
|
@@ -38351,6 +38351,90 @@ function formatDate(dateString) {
|
|
|
38351
38351
|
function formatPercent(n, decimals = 2) {
|
|
38352
38352
|
return `${n.toFixed(decimals)}%`;
|
|
38353
38353
|
}
|
|
38354
|
+
const COUNTRY_LOCALES = {
|
|
38355
|
+
US: "en-US",
|
|
38356
|
+
CA: "en-CA",
|
|
38357
|
+
GB: "en-GB",
|
|
38358
|
+
IE: "en-IE",
|
|
38359
|
+
AU: "en-AU",
|
|
38360
|
+
NZ: "en-NZ",
|
|
38361
|
+
FR: "fr-FR",
|
|
38362
|
+
BE: "fr-BE",
|
|
38363
|
+
LU: "fr-LU",
|
|
38364
|
+
DE: "de-DE",
|
|
38365
|
+
AT: "de-AT",
|
|
38366
|
+
CH: "de-CH",
|
|
38367
|
+
NL: "nl-NL",
|
|
38368
|
+
ES: "es-ES",
|
|
38369
|
+
IT: "it-IT",
|
|
38370
|
+
PT: "pt-PT",
|
|
38371
|
+
BR: "pt-BR",
|
|
38372
|
+
SE: "sv-SE",
|
|
38373
|
+
NO: "nb-NO",
|
|
38374
|
+
DK: "da-DK",
|
|
38375
|
+
FI: "fi-FI",
|
|
38376
|
+
PL: "pl-PL",
|
|
38377
|
+
JP: "ja-JP",
|
|
38378
|
+
CN: "zh-CN",
|
|
38379
|
+
IN: "en-IN",
|
|
38380
|
+
SG: "en-SG"
|
|
38381
|
+
};
|
|
38382
|
+
function localeForCountry(country) {
|
|
38383
|
+
if (!country) return "en-US";
|
|
38384
|
+
const key = country.toUpperCase();
|
|
38385
|
+
return COUNTRY_LOCALES[key] ?? "en-US";
|
|
38386
|
+
}
|
|
38387
|
+
const toNumber = (value) => {
|
|
38388
|
+
if (typeof value === "number") return value;
|
|
38389
|
+
if (value.trim() === "") return Number.NaN;
|
|
38390
|
+
const parsed = Number(value);
|
|
38391
|
+
return Number.isFinite(parsed) ? parsed : Number.NaN;
|
|
38392
|
+
};
|
|
38393
|
+
function formatMonetary(monetary, options = {}) {
|
|
38394
|
+
const {
|
|
38395
|
+
locale: explicitLocale,
|
|
38396
|
+
country,
|
|
38397
|
+
fallbackCurrency = "USD",
|
|
38398
|
+
compactWholeNumbers = true
|
|
38399
|
+
} = options;
|
|
38400
|
+
if (monetary === null || monetary === void 0) return "";
|
|
38401
|
+
let amount;
|
|
38402
|
+
let currency;
|
|
38403
|
+
if (typeof monetary === "number" || typeof monetary === "string") {
|
|
38404
|
+
amount = toNumber(monetary);
|
|
38405
|
+
currency = fallbackCurrency.toUpperCase();
|
|
38406
|
+
} else {
|
|
38407
|
+
amount = toNumber(monetary.amount);
|
|
38408
|
+
currency = (monetary.currency || fallbackCurrency).toUpperCase();
|
|
38409
|
+
}
|
|
38410
|
+
if (!Number.isFinite(amount)) return "";
|
|
38411
|
+
const locale = explicitLocale ?? localeForCountry(country);
|
|
38412
|
+
let nativeFractionDigits = 2;
|
|
38413
|
+
try {
|
|
38414
|
+
const resolved = new Intl.NumberFormat(locale, {
|
|
38415
|
+
style: "currency",
|
|
38416
|
+
currency
|
|
38417
|
+
}).resolvedOptions().maximumFractionDigits;
|
|
38418
|
+
if (typeof resolved === "number") nativeFractionDigits = resolved;
|
|
38419
|
+
} catch {
|
|
38420
|
+
}
|
|
38421
|
+
const isWhole = Number.isInteger(amount);
|
|
38422
|
+
const minimumFractionDigits = compactWholeNumbers && isWhole ? 0 : nativeFractionDigits;
|
|
38423
|
+
const subUnitThreshold = 10 ** -nativeFractionDigits;
|
|
38424
|
+
const subUnit = Math.abs(amount) > 0 && Math.abs(amount) < subUnitThreshold;
|
|
38425
|
+
const maximumFractionDigits = subUnit ? Math.max(6, nativeFractionDigits) : nativeFractionDigits;
|
|
38426
|
+
try {
|
|
38427
|
+
return new Intl.NumberFormat(locale, {
|
|
38428
|
+
style: "currency",
|
|
38429
|
+
currency,
|
|
38430
|
+
minimumFractionDigits,
|
|
38431
|
+
maximumFractionDigits
|
|
38432
|
+
}).format(amount);
|
|
38433
|
+
} catch {
|
|
38434
|
+
const fallbackDigits = subUnit ? maximumFractionDigits : minimumFractionDigits;
|
|
38435
|
+
return `${amount.toFixed(fallbackDigits)} ${currency}`;
|
|
38436
|
+
}
|
|
38437
|
+
}
|
|
38354
38438
|
const TABULAR_NUMS = { fontVariantNumeric: "tabular-nums" };
|
|
38355
38439
|
function Currency({ value, precise = false, currency, style, ...rest }) {
|
|
38356
38440
|
let formatted;
|
|
@@ -41150,6 +41234,7 @@ exports.fontSizes = fontSizes;
|
|
|
41150
41234
|
exports.formatCurrency = formatCurrency;
|
|
41151
41235
|
exports.formatCurrencyPrecise = formatCurrencyPrecise;
|
|
41152
41236
|
exports.formatDate = formatDate;
|
|
41237
|
+
exports.formatMonetary = formatMonetary;
|
|
41153
41238
|
exports.formatNumber = formatNumber;
|
|
41154
41239
|
exports.formatPercent = formatPercent;
|
|
41155
41240
|
exports.formatPhone = formatPhone;
|
|
@@ -41163,6 +41248,7 @@ exports.getWalletLabel = getWalletLabel;
|
|
|
41163
41248
|
exports.isEthereumAddress = isEthereumAddress;
|
|
41164
41249
|
exports.isRemovableWalletType = isRemovableWalletType;
|
|
41165
41250
|
exports.isSystemWalletType = isSystemWalletType;
|
|
41251
|
+
exports.localeForCountry = localeForCountry;
|
|
41166
41252
|
exports.neutralColors = neutralColors;
|
|
41167
41253
|
exports.normalizePhone = normalizePhone;
|
|
41168
41254
|
exports.normalizeWalletType = normalizeWalletType;
|