@lightsparkdev/core 1.2.6 → 1.2.8
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/CHANGELOG.md +14 -0
- package/dist/{chunk-CKJUUY2Z.js → chunk-NY4EJZNK.js} +121 -35
- package/dist/{index-COxEW2dD.d.cts → index-r0bUxDu_.d.cts} +31 -10
- package/dist/{index-COxEW2dD.d.ts → index-r0bUxDu_.d.ts} +31 -10
- package/dist/index.cjs +128 -38
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +10 -4
- package/dist/utils/index.cjs +123 -35
- package/dist/utils/index.d.cts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +5 -1
- package/package.json +1 -1
- package/src/requester/Requester.ts +5 -2
- package/src/utils/currency.ts +195 -42
- package/src/utils/locale.ts +2 -0
- package/src/utils/tests/currency.test.ts +183 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @lightsparkdev/core
|
|
2
2
|
|
|
3
|
+
## 1.2.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 47733a2: - Allow injecting a custom fetchImpl into the JS SDK. This is helpful for clients who need custom requesting logic, logging, etc.
|
|
8
|
+
|
|
9
|
+
## 1.2.7
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 56d359b: - PHP Currency Support Added:
|
|
14
|
+
– Updated packages/core/src/utils/currency.ts to include PHP as a valid currency unit. This involved extending the CurrencyUnit object, adding PHP conversion functions into the conversion maps (for Bitcoin, microbitcoin, millibitcoin, satoshi, etc.), and updating formatting logic (e.g. in formatCurrencyStr).
|
|
15
|
+
– Corresponding type definitions and helper functions (such as isCurrencyAmountInputObj and related mapping functions) were enhanced to support PHP, and tests in packages/core/src/utils/tests/currency.test.ts now verify PHP conversions.
|
|
16
|
+
|
|
3
17
|
## 1.2.6
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -407,6 +407,7 @@ var CurrencyUnit = {
|
|
|
407
407
|
MILLIBITCOIN: "MILLIBITCOIN",
|
|
408
408
|
USD: "USD",
|
|
409
409
|
MXN: "MXN",
|
|
410
|
+
PHP: "PHP",
|
|
410
411
|
Bitcoin: "BITCOIN",
|
|
411
412
|
Microbitcoin: "MICROBITCOIN",
|
|
412
413
|
Millibitcoin: "MILLIBITCOIN",
|
|
@@ -414,7 +415,8 @@ var CurrencyUnit = {
|
|
|
414
415
|
Nanobitcoin: "NANOBITCOIN",
|
|
415
416
|
Satoshi: "SATOSHI",
|
|
416
417
|
Usd: "USD",
|
|
417
|
-
Mxn: "MXN"
|
|
418
|
+
Mxn: "MXN",
|
|
419
|
+
Php: "PHP"
|
|
418
420
|
};
|
|
419
421
|
var standardUnitConversionObj = {
|
|
420
422
|
[CurrencyUnit.BITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc,
|
|
@@ -425,7 +427,8 @@ var standardUnitConversionObj = {
|
|
|
425
427
|
[CurrencyUnit.SATOSHI]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e8,
|
|
426
428
|
/* Converting between two different fiat types is not currently supported */
|
|
427
429
|
[CurrencyUnit.USD]: (v) => v,
|
|
428
|
-
[CurrencyUnit.MXN]: (v) => v
|
|
430
|
+
[CurrencyUnit.MXN]: (v) => v,
|
|
431
|
+
[CurrencyUnit.PHP]: (v) => v
|
|
429
432
|
};
|
|
430
433
|
var toBitcoinConversion = (v, unitsPerBtc = 1) => round(v * unitsPerBtc);
|
|
431
434
|
var toMicrobitcoinConversion = (v, unitsPerBtc = 1) => round(v / 1e6 * unitsPerBtc);
|
|
@@ -442,7 +445,8 @@ var CONVERSION_MAP = {
|
|
|
442
445
|
[CurrencyUnit.NANOBITCOIN]: (v) => v * 1e9,
|
|
443
446
|
[CurrencyUnit.SATOSHI]: (v) => v * 1e8,
|
|
444
447
|
[CurrencyUnit.USD]: toBitcoinConversion,
|
|
445
|
-
[CurrencyUnit.MXN]: toBitcoinConversion
|
|
448
|
+
[CurrencyUnit.MXN]: toBitcoinConversion,
|
|
449
|
+
[CurrencyUnit.PHP]: toBitcoinConversion
|
|
446
450
|
},
|
|
447
451
|
[CurrencyUnit.MICROBITCOIN]: {
|
|
448
452
|
[CurrencyUnit.BITCOIN]: (v) => v / 1e6,
|
|
@@ -452,7 +456,8 @@ var CONVERSION_MAP = {
|
|
|
452
456
|
[CurrencyUnit.NANOBITCOIN]: (v) => v * 1e3,
|
|
453
457
|
[CurrencyUnit.SATOSHI]: (v) => v * 100,
|
|
454
458
|
[CurrencyUnit.USD]: toMicrobitcoinConversion,
|
|
455
|
-
[CurrencyUnit.MXN]: toMicrobitcoinConversion
|
|
459
|
+
[CurrencyUnit.MXN]: toMicrobitcoinConversion,
|
|
460
|
+
[CurrencyUnit.PHP]: toMicrobitcoinConversion
|
|
456
461
|
},
|
|
457
462
|
[CurrencyUnit.MILLIBITCOIN]: {
|
|
458
463
|
[CurrencyUnit.BITCOIN]: (v) => v / 1e3,
|
|
@@ -462,7 +467,8 @@ var CONVERSION_MAP = {
|
|
|
462
467
|
[CurrencyUnit.NANOBITCOIN]: (v) => v * 1e6,
|
|
463
468
|
[CurrencyUnit.SATOSHI]: (v) => v * 1e5,
|
|
464
469
|
[CurrencyUnit.USD]: toMillibitcoinConversion,
|
|
465
|
-
[CurrencyUnit.MXN]: toMillibitcoinConversion
|
|
470
|
+
[CurrencyUnit.MXN]: toMillibitcoinConversion,
|
|
471
|
+
[CurrencyUnit.PHP]: toMillibitcoinConversion
|
|
466
472
|
},
|
|
467
473
|
[CurrencyUnit.MILLISATOSHI]: {
|
|
468
474
|
[CurrencyUnit.BITCOIN]: (v) => v / 1e11,
|
|
@@ -472,7 +478,8 @@ var CONVERSION_MAP = {
|
|
|
472
478
|
[CurrencyUnit.NANOBITCOIN]: (v) => v / 100,
|
|
473
479
|
[CurrencyUnit.SATOSHI]: (v) => v / 1e3,
|
|
474
480
|
[CurrencyUnit.USD]: toMillisatoshiConversion,
|
|
475
|
-
[CurrencyUnit.MXN]: toMillisatoshiConversion
|
|
481
|
+
[CurrencyUnit.MXN]: toMillisatoshiConversion,
|
|
482
|
+
[CurrencyUnit.PHP]: toMillisatoshiConversion
|
|
476
483
|
},
|
|
477
484
|
[CurrencyUnit.NANOBITCOIN]: {
|
|
478
485
|
[CurrencyUnit.BITCOIN]: (v) => v / 1e9,
|
|
@@ -482,7 +489,8 @@ var CONVERSION_MAP = {
|
|
|
482
489
|
[CurrencyUnit.NANOBITCOIN]: (v) => v,
|
|
483
490
|
[CurrencyUnit.SATOSHI]: (v) => v / 10,
|
|
484
491
|
[CurrencyUnit.USD]: toNanobitcoinConversion,
|
|
485
|
-
[CurrencyUnit.MXN]: toNanobitcoinConversion
|
|
492
|
+
[CurrencyUnit.MXN]: toNanobitcoinConversion,
|
|
493
|
+
[CurrencyUnit.PHP]: toNanobitcoinConversion
|
|
486
494
|
},
|
|
487
495
|
[CurrencyUnit.SATOSHI]: {
|
|
488
496
|
[CurrencyUnit.BITCOIN]: (v) => v / 1e8,
|
|
@@ -492,10 +500,12 @@ var CONVERSION_MAP = {
|
|
|
492
500
|
[CurrencyUnit.NANOBITCOIN]: (v) => v * 10,
|
|
493
501
|
[CurrencyUnit.SATOSHI]: (v) => v,
|
|
494
502
|
[CurrencyUnit.USD]: toSatoshiConversion,
|
|
495
|
-
[CurrencyUnit.MXN]: toSatoshiConversion
|
|
503
|
+
[CurrencyUnit.MXN]: toSatoshiConversion,
|
|
504
|
+
[CurrencyUnit.PHP]: toSatoshiConversion
|
|
496
505
|
},
|
|
497
506
|
[CurrencyUnit.USD]: standardUnitConversionObj,
|
|
498
|
-
[CurrencyUnit.MXN]: standardUnitConversionObj
|
|
507
|
+
[CurrencyUnit.MXN]: standardUnitConversionObj,
|
|
508
|
+
[CurrencyUnit.PHP]: standardUnitConversionObj
|
|
499
509
|
};
|
|
500
510
|
function convertCurrencyAmountValue(fromUnit, toUnit, amount, unitsPerBtc = 1) {
|
|
501
511
|
if (fromUnit === CurrencyUnit.FUTURE_VALUE || toUnit === CurrencyUnit.FUTURE_VALUE) {
|
|
@@ -526,6 +536,9 @@ var convertCurrencyAmount = (from, toUnit) => {
|
|
|
526
536
|
preferredCurrencyValueRounded: value
|
|
527
537
|
};
|
|
528
538
|
};
|
|
539
|
+
function isCurrencyAmountInputObj(arg) {
|
|
540
|
+
return typeof arg === "object" && arg !== null && "value" in arg && (typeof arg.value === "number" || typeof arg.value === "string" || arg.value === null) && "unit" in arg && typeof arg.unit === "string";
|
|
541
|
+
}
|
|
529
542
|
function isDeprecatedCurrencyAmountObj(arg) {
|
|
530
543
|
return typeof arg === "object" && arg !== null && "value" in arg && "unit" in arg;
|
|
531
544
|
}
|
|
@@ -533,7 +546,7 @@ function isCurrencyAmountObj(arg) {
|
|
|
533
546
|
return typeof arg === "object" && arg !== null && "original_value" in arg && "original_unit" in arg;
|
|
534
547
|
}
|
|
535
548
|
function isCurrencyAmountPreferenceObj(arg) {
|
|
536
|
-
return typeof arg === "object" && arg !== null && "preferred_currency_unit" in arg && "
|
|
549
|
+
return typeof arg === "object" && arg !== null && "original_unit" in arg && typeof arg.original_unit === "string" && "original_value" in arg && typeof arg.original_value === "number" && "preferred_currency_unit" in arg && typeof arg.preferred_currency_unit === "string" && "preferred_currency_value_approx" in arg && typeof arg.preferred_currency_value_approx === "number";
|
|
537
550
|
}
|
|
538
551
|
function isSDKCurrencyAmount(arg) {
|
|
539
552
|
return typeof arg === "object" && arg !== null && /* We can expect all SDK CurrencyAmount types to always have these exact properties: */
|
|
@@ -551,13 +564,10 @@ function getCurrencyAmount(currencyAmountArg) {
|
|
|
551
564
|
if (isSDKCurrencyAmount(currencyAmountArg)) {
|
|
552
565
|
value = currencyAmountArg.originalValue;
|
|
553
566
|
unit = currencyAmountArg.originalUnit;
|
|
554
|
-
} else if (isCurrencyAmountPreferenceObj(currencyAmountArg)) {
|
|
555
|
-
value = asNumber(currencyAmountArg.preferred_currency_value_rounded);
|
|
556
|
-
unit = currencyAmountArg.preferred_currency_unit;
|
|
557
567
|
} else if (isCurrencyAmountObj(currencyAmountArg)) {
|
|
558
568
|
value = asNumber(currencyAmountArg.original_value);
|
|
559
569
|
unit = currencyAmountArg.original_unit;
|
|
560
|
-
} else if (isDeprecatedCurrencyAmountObj(currencyAmountArg)) {
|
|
570
|
+
} else if (isCurrencyAmountInputObj(currencyAmountArg) || isDeprecatedCurrencyAmountObj(currencyAmountArg)) {
|
|
561
571
|
value = asNumber(currencyAmountArg.value);
|
|
562
572
|
unit = currencyAmountArg.unit;
|
|
563
573
|
}
|
|
@@ -566,23 +576,61 @@ function getCurrencyAmount(currencyAmountArg) {
|
|
|
566
576
|
unit: unit || CurrencyUnit.SATOSHI
|
|
567
577
|
};
|
|
568
578
|
}
|
|
579
|
+
function convertCurrencyAmountValues(fromUnit, amount, unitsPerBtc = 1, conversionOverride) {
|
|
580
|
+
const convert = convertCurrencyAmountValue;
|
|
581
|
+
const namesToUnits = {
|
|
582
|
+
sats: CurrencyUnit.SATOSHI,
|
|
583
|
+
btc: CurrencyUnit.BITCOIN,
|
|
584
|
+
msats: CurrencyUnit.MILLISATOSHI,
|
|
585
|
+
usd: CurrencyUnit.USD,
|
|
586
|
+
mxn: CurrencyUnit.MXN,
|
|
587
|
+
php: CurrencyUnit.PHP,
|
|
588
|
+
mibtc: CurrencyUnit.MICROBITCOIN,
|
|
589
|
+
mlbtc: CurrencyUnit.MILLIBITCOIN,
|
|
590
|
+
nbtc: CurrencyUnit.NANOBITCOIN
|
|
591
|
+
};
|
|
592
|
+
return Object.entries(namesToUnits).reduce(
|
|
593
|
+
(acc, [name, unit]) => {
|
|
594
|
+
if (conversionOverride && unit === conversionOverride.unit) {
|
|
595
|
+
acc[name] = conversionOverride.convertedValue;
|
|
596
|
+
} else {
|
|
597
|
+
acc[name] = convert(
|
|
598
|
+
fromUnit,
|
|
599
|
+
unit,
|
|
600
|
+
amount,
|
|
601
|
+
unitsPerBtc
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
return acc;
|
|
605
|
+
},
|
|
606
|
+
{}
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
function getPreferredConversionOverride(currencyAmountArg) {
|
|
610
|
+
if (isCurrencyAmountPreferenceObj(currencyAmountArg)) {
|
|
611
|
+
return {
|
|
612
|
+
unit: currencyAmountArg.preferred_currency_unit,
|
|
613
|
+
convertedValue: currencyAmountArg.preferred_currency_value_approx
|
|
614
|
+
};
|
|
615
|
+
} else if (isSDKCurrencyAmount(currencyAmountArg)) {
|
|
616
|
+
return {
|
|
617
|
+
unit: currencyAmountArg.preferredCurrencyUnit,
|
|
618
|
+
convertedValue: currencyAmountArg.preferredCurrencyValueApprox
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
return void 0;
|
|
622
|
+
}
|
|
569
623
|
function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
|
|
570
624
|
const { value, unit } = getCurrencyAmount(currencyAmountArg);
|
|
571
|
-
const
|
|
572
|
-
const sats =
|
|
573
|
-
const btc = convert(unit, CurrencyUnit.BITCOIN, value, unitsPerBtc);
|
|
574
|
-
const msats = convert(unit, CurrencyUnit.MILLISATOSHI, value, unitsPerBtc);
|
|
575
|
-
const usd = convert(unit, CurrencyUnit.USD, value, unitsPerBtc);
|
|
576
|
-
const mxn = convert(unit, CurrencyUnit.MXN, value, unitsPerBtc);
|
|
577
|
-
const mibtc = convert(unit, CurrencyUnit.MICROBITCOIN, value, unitsPerBtc);
|
|
578
|
-
const mlbtc = convert(unit, CurrencyUnit.MILLIBITCOIN, value, unitsPerBtc);
|
|
579
|
-
const nbtc = convert(unit, CurrencyUnit.NANOBITCOIN, value, unitsPerBtc);
|
|
625
|
+
const conversionOverride = getPreferredConversionOverride(currencyAmountArg);
|
|
626
|
+
const { sats, msats, btc, usd, mxn, php, mibtc, mlbtc, nbtc } = convertCurrencyAmountValues(unit, value, unitsPerBtc, conversionOverride);
|
|
580
627
|
const mapWithCurrencyUnits = {
|
|
581
628
|
[CurrencyUnit.BITCOIN]: btc,
|
|
582
629
|
[CurrencyUnit.SATOSHI]: sats,
|
|
583
630
|
[CurrencyUnit.MILLISATOSHI]: msats,
|
|
584
631
|
[CurrencyUnit.USD]: usd,
|
|
585
632
|
[CurrencyUnit.MXN]: mxn,
|
|
633
|
+
[CurrencyUnit.PHP]: php,
|
|
586
634
|
[CurrencyUnit.MICROBITCOIN]: mibtc,
|
|
587
635
|
[CurrencyUnit.MILLIBITCOIN]: mlbtc,
|
|
588
636
|
[CurrencyUnit.NANOBITCOIN]: nbtc,
|
|
@@ -620,6 +668,10 @@ function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
|
|
|
620
668
|
value: mxn,
|
|
621
669
|
unit: CurrencyUnit.MXN
|
|
622
670
|
}),
|
|
671
|
+
[CurrencyUnit.PHP]: formatCurrencyStr({
|
|
672
|
+
value: php,
|
|
673
|
+
unit: CurrencyUnit.PHP
|
|
674
|
+
}),
|
|
623
675
|
[CurrencyUnit.FUTURE_VALUE]: "-"
|
|
624
676
|
}
|
|
625
677
|
};
|
|
@@ -674,8 +726,16 @@ var abbrCurrencyUnit = (unit) => {
|
|
|
674
726
|
return "SAT";
|
|
675
727
|
case CurrencyUnit.MILLISATOSHI:
|
|
676
728
|
return "MSAT";
|
|
729
|
+
case CurrencyUnit.MILLIBITCOIN:
|
|
730
|
+
return "mBTC";
|
|
731
|
+
case CurrencyUnit.MICROBITCOIN:
|
|
732
|
+
return "\u03BCBTC";
|
|
677
733
|
case CurrencyUnit.USD:
|
|
678
734
|
return "USD";
|
|
735
|
+
case CurrencyUnit.MXN:
|
|
736
|
+
return "MXN";
|
|
737
|
+
case CurrencyUnit.PHP:
|
|
738
|
+
return "PHP";
|
|
679
739
|
}
|
|
680
740
|
return "Unsupported CurrencyUnit";
|
|
681
741
|
};
|
|
@@ -683,7 +743,8 @@ var defaultOptions = {
|
|
|
683
743
|
/* undefined indicates to use default precision for unit defined below */
|
|
684
744
|
precision: void 0,
|
|
685
745
|
compact: false,
|
|
686
|
-
showBtcSymbol: false
|
|
746
|
+
showBtcSymbol: false,
|
|
747
|
+
append: void 0
|
|
687
748
|
};
|
|
688
749
|
function formatCurrencyStr(amount, options) {
|
|
689
750
|
const { precision, compact, showBtcSymbol } = {
|
|
@@ -693,7 +754,12 @@ function formatCurrencyStr(amount, options) {
|
|
|
693
754
|
const currencyAmount = getCurrencyAmount(amount);
|
|
694
755
|
let { value: num } = currencyAmount;
|
|
695
756
|
const { unit } = currencyAmount;
|
|
696
|
-
|
|
757
|
+
const centCurrencies = [
|
|
758
|
+
CurrencyUnit.USD,
|
|
759
|
+
CurrencyUnit.MXN,
|
|
760
|
+
CurrencyUnit.PHP
|
|
761
|
+
];
|
|
762
|
+
if (centCurrencies.includes(unit)) {
|
|
697
763
|
num = num / 100;
|
|
698
764
|
}
|
|
699
765
|
function getDefaultMaxFractionDigits(defaultDigits, fullPrecisionDigits) {
|
|
@@ -709,34 +775,52 @@ function formatCurrencyStr(amount, options) {
|
|
|
709
775
|
}
|
|
710
776
|
const symbol = !showBtcSymbol ? "" : unit === CurrencyUnit.BITCOIN ? "\uE903" : unit === CurrencyUnit.SATOSHI ? "\uE902" : "";
|
|
711
777
|
const currentLocale = getCurrentLocale();
|
|
778
|
+
let formattedStr = "";
|
|
712
779
|
switch (unit) {
|
|
780
|
+
case CurrencyUnit.MXN:
|
|
781
|
+
case CurrencyUnit.USD:
|
|
782
|
+
case CurrencyUnit.PHP:
|
|
783
|
+
formattedStr = num.toLocaleString(currentLocale, {
|
|
784
|
+
style: "currency",
|
|
785
|
+
currency: unit,
|
|
786
|
+
currencyDisplay: "narrowSymbol",
|
|
787
|
+
notation: compact ? "compact" : void 0,
|
|
788
|
+
maximumFractionDigits: getDefaultMaxFractionDigits(2, 2)
|
|
789
|
+
});
|
|
790
|
+
break;
|
|
713
791
|
case CurrencyUnit.BITCOIN:
|
|
714
|
-
|
|
792
|
+
formattedStr = `${symbol}${num.toLocaleString(currentLocale, {
|
|
715
793
|
notation: compact ? "compact" : void 0,
|
|
716
794
|
maximumFractionDigits: getDefaultMaxFractionDigits(4, 8)
|
|
717
795
|
})}`;
|
|
796
|
+
break;
|
|
718
797
|
case CurrencyUnit.SATOSHI:
|
|
719
|
-
|
|
798
|
+
formattedStr = `${symbol}${num.toLocaleString(currentLocale, {
|
|
720
799
|
notation: compact ? "compact" : void 0,
|
|
721
800
|
maximumFractionDigits: getDefaultMaxFractionDigits(0, 3)
|
|
722
801
|
})}`;
|
|
802
|
+
break;
|
|
723
803
|
case CurrencyUnit.MILLISATOSHI:
|
|
724
804
|
case CurrencyUnit.MICROBITCOIN:
|
|
725
805
|
case CurrencyUnit.MILLIBITCOIN:
|
|
726
806
|
case CurrencyUnit.NANOBITCOIN:
|
|
727
807
|
default:
|
|
728
|
-
|
|
808
|
+
formattedStr = `${symbol}${num.toLocaleString(currentLocale, {
|
|
729
809
|
notation: compact ? "compact" : void 0,
|
|
730
810
|
maximumFractionDigits: getDefaultMaxFractionDigits(0, 0)
|
|
731
811
|
})}`;
|
|
732
|
-
case CurrencyUnit.USD:
|
|
733
|
-
return num.toLocaleString(currentLocale, {
|
|
734
|
-
style: "currency",
|
|
735
|
-
currency: defaultCurrencyCode,
|
|
736
|
-
notation: compact ? "compact" : void 0,
|
|
737
|
-
maximumFractionDigits: getDefaultMaxFractionDigits(2, 2)
|
|
738
|
-
});
|
|
739
812
|
}
|
|
813
|
+
if (options?.appendUnits) {
|
|
814
|
+
const localeCurrencyCode = localeToCurrencyCode(currentLocale);
|
|
815
|
+
if (unit === localeCurrencyCode && !options.appendUnits.showForCurrentLocaleUnit) {
|
|
816
|
+
return formattedStr;
|
|
817
|
+
}
|
|
818
|
+
const unitStr = abbrCurrencyUnit(unit);
|
|
819
|
+
const unitSuffix = options.appendUnits.plural && num > 1 ? "s" : "";
|
|
820
|
+
const unitStrWithSuffix = `${unitStr}${unitSuffix}`;
|
|
821
|
+
formattedStr += ` ${options.appendUnits.lowercase ? unitStrWithSuffix.toLowerCase() : unitStrWithSuffix}`;
|
|
822
|
+
}
|
|
823
|
+
return formattedStr;
|
|
740
824
|
}
|
|
741
825
|
function separateCurrencyStrParts(currencyStr) {
|
|
742
826
|
const symbol = currencyStr.replace(/[0-9\s\u00a0.,]/g, "");
|
|
@@ -983,10 +1067,12 @@ export {
|
|
|
983
1067
|
CurrencyUnit,
|
|
984
1068
|
convertCurrencyAmountValue,
|
|
985
1069
|
convertCurrencyAmount,
|
|
1070
|
+
isCurrencyAmountInputObj,
|
|
986
1071
|
isDeprecatedCurrencyAmountObj,
|
|
987
1072
|
isCurrencyAmountObj,
|
|
988
1073
|
isCurrencyAmountPreferenceObj,
|
|
989
1074
|
isSDKCurrencyAmount,
|
|
1075
|
+
getCurrencyAmount,
|
|
990
1076
|
mapCurrencyAmount,
|
|
991
1077
|
isCurrencyMap,
|
|
992
1078
|
abbrCurrencyUnit,
|
|
@@ -25,6 +25,7 @@ declare const CurrencyUnit: {
|
|
|
25
25
|
readonly MILLIBITCOIN: "MILLIBITCOIN";
|
|
26
26
|
readonly USD: "USD";
|
|
27
27
|
readonly MXN: "MXN";
|
|
28
|
+
readonly PHP: "PHP";
|
|
28
29
|
readonly Bitcoin: "BITCOIN";
|
|
29
30
|
readonly Microbitcoin: "MICROBITCOIN";
|
|
30
31
|
readonly Millibitcoin: "MILLIBITCOIN";
|
|
@@ -33,6 +34,7 @@ declare const CurrencyUnit: {
|
|
|
33
34
|
readonly Satoshi: "SATOSHI";
|
|
34
35
|
readonly Usd: "USD";
|
|
35
36
|
readonly Mxn: "MXN";
|
|
37
|
+
readonly Php: "PHP";
|
|
36
38
|
};
|
|
37
39
|
type CurrencyUnitType = (typeof CurrencyUnit)[keyof typeof CurrencyUnit];
|
|
38
40
|
type SDKCurrencyAmountType = {
|
|
@@ -56,6 +58,7 @@ type CurrencyMap = {
|
|
|
56
58
|
[CurrencyUnit.NANOBITCOIN]: number;
|
|
57
59
|
[CurrencyUnit.USD]: number;
|
|
58
60
|
[CurrencyUnit.MXN]: number;
|
|
61
|
+
[CurrencyUnit.PHP]: number;
|
|
59
62
|
[CurrencyUnit.FUTURE_VALUE]: number;
|
|
60
63
|
formatted: {
|
|
61
64
|
sats: string;
|
|
@@ -69,6 +72,7 @@ type CurrencyMap = {
|
|
|
69
72
|
[CurrencyUnit.NANOBITCOIN]: string;
|
|
70
73
|
[CurrencyUnit.USD]: string;
|
|
71
74
|
[CurrencyUnit.MXN]: string;
|
|
75
|
+
[CurrencyUnit.PHP]: string;
|
|
72
76
|
[CurrencyUnit.FUTURE_VALUE]: string;
|
|
73
77
|
};
|
|
74
78
|
isZero: boolean;
|
|
@@ -77,33 +81,50 @@ type CurrencyMap = {
|
|
|
77
81
|
isEqualTo: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
|
|
78
82
|
type: "CurrencyMap";
|
|
79
83
|
};
|
|
84
|
+
type CurrencyAmountInputObj = {
|
|
85
|
+
value: number | string | null;
|
|
86
|
+
unit: CurrencyUnitType;
|
|
87
|
+
};
|
|
80
88
|
type DeprecatedCurrencyAmountObj = {
|
|
81
|
-
value?: number
|
|
89
|
+
value?: number;
|
|
82
90
|
unit?: CurrencyUnitType;
|
|
83
|
-
__typename?: "CurrencyAmount"
|
|
91
|
+
__typename?: "CurrencyAmount";
|
|
84
92
|
};
|
|
85
93
|
type CurrencyAmountObj = {
|
|
86
|
-
original_value?: number
|
|
94
|
+
original_value?: number;
|
|
87
95
|
original_unit?: CurrencyUnitType;
|
|
88
|
-
__typename?: "CurrencyAmount"
|
|
96
|
+
__typename?: "CurrencyAmount";
|
|
89
97
|
};
|
|
90
98
|
type CurrencyAmountPreferenceObj = {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
99
|
+
original_value: number;
|
|
100
|
+
original_unit: CurrencyUnitType;
|
|
101
|
+
preferred_currency_unit: CurrencyUnitType;
|
|
102
|
+
preferred_currency_value_approx: number;
|
|
103
|
+
__typename?: "CurrencyAmount";
|
|
94
104
|
};
|
|
95
|
-
type CurrencyAmountArg = DeprecatedCurrencyAmountObj | CurrencyAmountObj | CurrencyAmountPreferenceObj | SDKCurrencyAmountType | undefined | null;
|
|
105
|
+
type CurrencyAmountArg = CurrencyAmountInputObj | DeprecatedCurrencyAmountObj | CurrencyAmountObj | CurrencyAmountPreferenceObj | SDKCurrencyAmountType | undefined | null;
|
|
106
|
+
declare function isCurrencyAmountInputObj(arg: unknown): arg is CurrencyAmountInputObj;
|
|
96
107
|
declare function isDeprecatedCurrencyAmountObj(arg: unknown): arg is DeprecatedCurrencyAmountObj;
|
|
97
108
|
declare function isCurrencyAmountObj(arg: unknown): arg is CurrencyAmountObj;
|
|
98
109
|
declare function isCurrencyAmountPreferenceObj(arg: unknown): arg is CurrencyAmountPreferenceObj;
|
|
99
110
|
declare function isSDKCurrencyAmount(arg: unknown): arg is SDKCurrencyAmountType;
|
|
111
|
+
declare function getCurrencyAmount(currencyAmountArg: CurrencyAmountArg): {
|
|
112
|
+
value: number;
|
|
113
|
+
unit: CurrencyUnitType;
|
|
114
|
+
};
|
|
100
115
|
declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, unitsPerBtc?: number): CurrencyMap;
|
|
101
116
|
declare const isCurrencyMap: (currencyMap: unknown) => currencyMap is CurrencyMap;
|
|
102
|
-
declare const abbrCurrencyUnit: (unit: CurrencyUnitType) => "USD" | "BTC" | "SAT" | "MSAT" | "Unsupported CurrencyUnit";
|
|
117
|
+
declare const abbrCurrencyUnit: (unit: CurrencyUnitType) => "USD" | "MXN" | "PHP" | "BTC" | "SAT" | "MSAT" | "mBTC" | "μBTC" | "Unsupported CurrencyUnit";
|
|
118
|
+
type AppendUnitsOptions = {
|
|
119
|
+
plural?: boolean | undefined;
|
|
120
|
+
lowercase?: boolean | undefined;
|
|
121
|
+
showForCurrentLocaleUnit?: boolean | undefined;
|
|
122
|
+
};
|
|
103
123
|
type FormatCurrencyStrOptions = {
|
|
104
124
|
precision?: number | "full" | undefined;
|
|
105
125
|
compact?: boolean | undefined;
|
|
106
126
|
showBtcSymbol?: boolean | undefined;
|
|
127
|
+
appendUnits?: AppendUnitsOptions | undefined;
|
|
107
128
|
};
|
|
108
129
|
declare function formatCurrencyStr(amount: CurrencyAmountArg, options?: FormatCurrencyStrOptions): string;
|
|
109
130
|
declare function separateCurrencyStrParts(currencyStr: string): {
|
|
@@ -266,4 +287,4 @@ declare function lsidToUUID(lsid: string): string;
|
|
|
266
287
|
declare function isUint8Array(value: unknown): value is Uint8Array;
|
|
267
288
|
declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
268
289
|
|
|
269
|
-
export {
|
|
290
|
+
export { isNumber as $, type AppendUnitsOptions as A, localeToCurrencySymbol as B, ConfigKeys as C, type DeprecatedCurrencyAmountObj as D, isBrowser as E, isNode as F, isTest as G, isError as H, isErrorWithMessage as I, getErrorMsg as J, isErrorMsg as K, errorToJSON as L, bytesToHex as M, hexToBytes as N, getCurrentLocale as O, countryCodesToCurrencyCodes as P, type CurrencyLocales as Q, type CurrencyCodes as R, type SDKCurrencyAmountType as S, localeToCurrencyCode as T, getLocalStorageConfigItem as U, getLocalStorageBoolean as V, setLocalStorageBoolean as W, deleteLocalStorageItem as X, clamp as Y, linearInterpolate as Z, round as _, b64encode as a, pollUntil as a0, sleep as a1, lsidToUUID as a2, isUint8Array as a3, isObject as a4, type Maybe as a5, type ExpandRecursively as a6, type ById as a7, type OmitTypename as a8, isType as a9, type DeepPartial as aa, type JSONLiteral as ab, type JSONType as ac, type JSONObject as ad, type NN as ae, notNullUndefined as af, type PartialBy as ag, type Complete as ah, type RequiredKeys as ai, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, ensureArray as e, CurrencyUnit as f, type CurrencyUnitType as g, convertCurrencyAmountValue as h, convertCurrencyAmount as i, type CurrencyMap as j, type CurrencyAmountInputObj as k, type CurrencyAmountObj as l, type CurrencyAmountPreferenceObj as m, type CurrencyAmountArg as n, isCurrencyAmountInputObj as o, isDeprecatedCurrencyAmountObj as p, isCurrencyAmountObj as q, isCurrencyAmountPreferenceObj as r, isSDKCurrencyAmount as s, getCurrencyAmount as t, urlsafe_b64decode as u, mapCurrencyAmount as v, isCurrencyMap as w, abbrCurrencyUnit as x, formatCurrencyStr as y, separateCurrencyStrParts as z };
|
|
@@ -25,6 +25,7 @@ declare const CurrencyUnit: {
|
|
|
25
25
|
readonly MILLIBITCOIN: "MILLIBITCOIN";
|
|
26
26
|
readonly USD: "USD";
|
|
27
27
|
readonly MXN: "MXN";
|
|
28
|
+
readonly PHP: "PHP";
|
|
28
29
|
readonly Bitcoin: "BITCOIN";
|
|
29
30
|
readonly Microbitcoin: "MICROBITCOIN";
|
|
30
31
|
readonly Millibitcoin: "MILLIBITCOIN";
|
|
@@ -33,6 +34,7 @@ declare const CurrencyUnit: {
|
|
|
33
34
|
readonly Satoshi: "SATOSHI";
|
|
34
35
|
readonly Usd: "USD";
|
|
35
36
|
readonly Mxn: "MXN";
|
|
37
|
+
readonly Php: "PHP";
|
|
36
38
|
};
|
|
37
39
|
type CurrencyUnitType = (typeof CurrencyUnit)[keyof typeof CurrencyUnit];
|
|
38
40
|
type SDKCurrencyAmountType = {
|
|
@@ -56,6 +58,7 @@ type CurrencyMap = {
|
|
|
56
58
|
[CurrencyUnit.NANOBITCOIN]: number;
|
|
57
59
|
[CurrencyUnit.USD]: number;
|
|
58
60
|
[CurrencyUnit.MXN]: number;
|
|
61
|
+
[CurrencyUnit.PHP]: number;
|
|
59
62
|
[CurrencyUnit.FUTURE_VALUE]: number;
|
|
60
63
|
formatted: {
|
|
61
64
|
sats: string;
|
|
@@ -69,6 +72,7 @@ type CurrencyMap = {
|
|
|
69
72
|
[CurrencyUnit.NANOBITCOIN]: string;
|
|
70
73
|
[CurrencyUnit.USD]: string;
|
|
71
74
|
[CurrencyUnit.MXN]: string;
|
|
75
|
+
[CurrencyUnit.PHP]: string;
|
|
72
76
|
[CurrencyUnit.FUTURE_VALUE]: string;
|
|
73
77
|
};
|
|
74
78
|
isZero: boolean;
|
|
@@ -77,33 +81,50 @@ type CurrencyMap = {
|
|
|
77
81
|
isEqualTo: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
|
|
78
82
|
type: "CurrencyMap";
|
|
79
83
|
};
|
|
84
|
+
type CurrencyAmountInputObj = {
|
|
85
|
+
value: number | string | null;
|
|
86
|
+
unit: CurrencyUnitType;
|
|
87
|
+
};
|
|
80
88
|
type DeprecatedCurrencyAmountObj = {
|
|
81
|
-
value?: number
|
|
89
|
+
value?: number;
|
|
82
90
|
unit?: CurrencyUnitType;
|
|
83
|
-
__typename?: "CurrencyAmount"
|
|
91
|
+
__typename?: "CurrencyAmount";
|
|
84
92
|
};
|
|
85
93
|
type CurrencyAmountObj = {
|
|
86
|
-
original_value?: number
|
|
94
|
+
original_value?: number;
|
|
87
95
|
original_unit?: CurrencyUnitType;
|
|
88
|
-
__typename?: "CurrencyAmount"
|
|
96
|
+
__typename?: "CurrencyAmount";
|
|
89
97
|
};
|
|
90
98
|
type CurrencyAmountPreferenceObj = {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
99
|
+
original_value: number;
|
|
100
|
+
original_unit: CurrencyUnitType;
|
|
101
|
+
preferred_currency_unit: CurrencyUnitType;
|
|
102
|
+
preferred_currency_value_approx: number;
|
|
103
|
+
__typename?: "CurrencyAmount";
|
|
94
104
|
};
|
|
95
|
-
type CurrencyAmountArg = DeprecatedCurrencyAmountObj | CurrencyAmountObj | CurrencyAmountPreferenceObj | SDKCurrencyAmountType | undefined | null;
|
|
105
|
+
type CurrencyAmountArg = CurrencyAmountInputObj | DeprecatedCurrencyAmountObj | CurrencyAmountObj | CurrencyAmountPreferenceObj | SDKCurrencyAmountType | undefined | null;
|
|
106
|
+
declare function isCurrencyAmountInputObj(arg: unknown): arg is CurrencyAmountInputObj;
|
|
96
107
|
declare function isDeprecatedCurrencyAmountObj(arg: unknown): arg is DeprecatedCurrencyAmountObj;
|
|
97
108
|
declare function isCurrencyAmountObj(arg: unknown): arg is CurrencyAmountObj;
|
|
98
109
|
declare function isCurrencyAmountPreferenceObj(arg: unknown): arg is CurrencyAmountPreferenceObj;
|
|
99
110
|
declare function isSDKCurrencyAmount(arg: unknown): arg is SDKCurrencyAmountType;
|
|
111
|
+
declare function getCurrencyAmount(currencyAmountArg: CurrencyAmountArg): {
|
|
112
|
+
value: number;
|
|
113
|
+
unit: CurrencyUnitType;
|
|
114
|
+
};
|
|
100
115
|
declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, unitsPerBtc?: number): CurrencyMap;
|
|
101
116
|
declare const isCurrencyMap: (currencyMap: unknown) => currencyMap is CurrencyMap;
|
|
102
|
-
declare const abbrCurrencyUnit: (unit: CurrencyUnitType) => "USD" | "BTC" | "SAT" | "MSAT" | "Unsupported CurrencyUnit";
|
|
117
|
+
declare const abbrCurrencyUnit: (unit: CurrencyUnitType) => "USD" | "MXN" | "PHP" | "BTC" | "SAT" | "MSAT" | "mBTC" | "μBTC" | "Unsupported CurrencyUnit";
|
|
118
|
+
type AppendUnitsOptions = {
|
|
119
|
+
plural?: boolean | undefined;
|
|
120
|
+
lowercase?: boolean | undefined;
|
|
121
|
+
showForCurrentLocaleUnit?: boolean | undefined;
|
|
122
|
+
};
|
|
103
123
|
type FormatCurrencyStrOptions = {
|
|
104
124
|
precision?: number | "full" | undefined;
|
|
105
125
|
compact?: boolean | undefined;
|
|
106
126
|
showBtcSymbol?: boolean | undefined;
|
|
127
|
+
appendUnits?: AppendUnitsOptions | undefined;
|
|
107
128
|
};
|
|
108
129
|
declare function formatCurrencyStr(amount: CurrencyAmountArg, options?: FormatCurrencyStrOptions): string;
|
|
109
130
|
declare function separateCurrencyStrParts(currencyStr: string): {
|
|
@@ -266,4 +287,4 @@ declare function lsidToUUID(lsid: string): string;
|
|
|
266
287
|
declare function isUint8Array(value: unknown): value is Uint8Array;
|
|
267
288
|
declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
268
289
|
|
|
269
|
-
export {
|
|
290
|
+
export { isNumber as $, type AppendUnitsOptions as A, localeToCurrencySymbol as B, ConfigKeys as C, type DeprecatedCurrencyAmountObj as D, isBrowser as E, isNode as F, isTest as G, isError as H, isErrorWithMessage as I, getErrorMsg as J, isErrorMsg as K, errorToJSON as L, bytesToHex as M, hexToBytes as N, getCurrentLocale as O, countryCodesToCurrencyCodes as P, type CurrencyLocales as Q, type CurrencyCodes as R, type SDKCurrencyAmountType as S, localeToCurrencyCode as T, getLocalStorageConfigItem as U, getLocalStorageBoolean as V, setLocalStorageBoolean as W, deleteLocalStorageItem as X, clamp as Y, linearInterpolate as Z, round as _, b64encode as a, pollUntil as a0, sleep as a1, lsidToUUID as a2, isUint8Array as a3, isObject as a4, type Maybe as a5, type ExpandRecursively as a6, type ById as a7, type OmitTypename as a8, isType as a9, type DeepPartial as aa, type JSONLiteral as ab, type JSONType as ac, type JSONObject as ad, type NN as ae, notNullUndefined as af, type PartialBy as ag, type Complete as ah, type RequiredKeys as ai, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, ensureArray as e, CurrencyUnit as f, type CurrencyUnitType as g, convertCurrencyAmountValue as h, convertCurrencyAmount as i, type CurrencyMap as j, type CurrencyAmountInputObj as k, type CurrencyAmountObj as l, type CurrencyAmountPreferenceObj as m, type CurrencyAmountArg as n, isCurrencyAmountInputObj as o, isDeprecatedCurrencyAmountObj as p, isCurrencyAmountObj as q, isCurrencyAmountPreferenceObj as r, isSDKCurrencyAmount as s, getCurrencyAmount as t, urlsafe_b64decode as u, mapCurrencyAmount as v, isCurrencyMap as w, abbrCurrencyUnit as x, formatCurrencyStr as y, separateCurrencyStrParts as z };
|