arky-sdk 0.4.25 → 0.4.26
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/index.cjs +37 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +37 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1430,11 +1430,43 @@ function formatCurrency(amount, currencyCode, locale = "en") {
|
|
|
1430
1430
|
currency: currencyCode.toUpperCase()
|
|
1431
1431
|
}).format(amount);
|
|
1432
1432
|
}
|
|
1433
|
-
function
|
|
1434
|
-
|
|
1433
|
+
function getMinorUnits(currency) {
|
|
1434
|
+
try {
|
|
1435
|
+
const formatter = new Intl.NumberFormat("en", {
|
|
1436
|
+
style: "currency",
|
|
1437
|
+
currency: currency.toUpperCase()
|
|
1438
|
+
});
|
|
1439
|
+
const parts = formatter.formatToParts(1.11);
|
|
1440
|
+
const fractionPart = parts.find((p) => p.type === "fraction");
|
|
1441
|
+
return fractionPart?.value.length ?? 2;
|
|
1442
|
+
} catch {
|
|
1443
|
+
return 2;
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
function convertToMajor(minorAmount, currency) {
|
|
1447
|
+
const units = getMinorUnits(currency);
|
|
1448
|
+
return minorAmount / Math.pow(10, units);
|
|
1449
|
+
}
|
|
1450
|
+
function getCurrencySymbol(currency) {
|
|
1451
|
+
try {
|
|
1452
|
+
return new Intl.NumberFormat("en", {
|
|
1453
|
+
style: "currency",
|
|
1454
|
+
currency: currency.toUpperCase(),
|
|
1455
|
+
currencyDisplay: "narrowSymbol"
|
|
1456
|
+
}).formatToParts(0).find((p) => p.type === "currency")?.value || currency.toUpperCase();
|
|
1457
|
+
} catch {
|
|
1458
|
+
return currency.toUpperCase();
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
function getCurrencyName(currency) {
|
|
1462
|
+
try {
|
|
1463
|
+
return new Intl.DisplayNames(["en"], { type: "currency" }).of(currency.toUpperCase()) || currency.toUpperCase();
|
|
1464
|
+
} catch {
|
|
1465
|
+
return currency.toUpperCase();
|
|
1466
|
+
}
|
|
1435
1467
|
}
|
|
1436
1468
|
function formatMinor(amountMinor, currency) {
|
|
1437
|
-
return formatCurrency(convertToMajor(amountMinor), currency);
|
|
1469
|
+
return formatCurrency(convertToMajor(amountMinor, currency), currency);
|
|
1438
1470
|
}
|
|
1439
1471
|
function formatPayment(payment) {
|
|
1440
1472
|
return formatMinor(payment.total, payment.currency);
|
|
@@ -1725,6 +1757,8 @@ async function createArkySDK(config) {
|
|
|
1725
1757
|
getPriceAmount: (prices) => getPriceAmount(prices, apiConfig.market),
|
|
1726
1758
|
formatPayment,
|
|
1727
1759
|
formatMinor,
|
|
1760
|
+
getCurrencySymbol,
|
|
1761
|
+
getCurrencyName,
|
|
1728
1762
|
validatePhoneNumber,
|
|
1729
1763
|
tzGroups,
|
|
1730
1764
|
findTimeZone,
|