@schukai/monster 3.18.0 → 3.19.0
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/package.json
CHANGED
|
@@ -576,6 +576,32 @@ function transform(value) {
|
|
|
576
576
|
|
|
577
577
|
return map.get(value);
|
|
578
578
|
|
|
579
|
+
case "money":
|
|
580
|
+
case "currency":
|
|
581
|
+
|
|
582
|
+
try {
|
|
583
|
+
locale = getLocaleOfDocument();
|
|
584
|
+
} catch (e) {
|
|
585
|
+
throw new Error("unsupported locale or missing format (" + e.message + ")");
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const currency = value.substring(0, 3);
|
|
589
|
+
if(!currency) {
|
|
590
|
+
throw new Error("missing currency parameter");
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const maximumFractionDigits = args?.[0] || 2;
|
|
594
|
+
const roundingIncrement = args?.[1] || 5;
|
|
595
|
+
|
|
596
|
+
const nf = new Intl.NumberFormat(locale, {
|
|
597
|
+
style: "currency",
|
|
598
|
+
currency: currency,
|
|
599
|
+
maximumFractionDigits: maximumFractionDigits,
|
|
600
|
+
roundingIncrement: roundingIncrement,
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
return nf.format(value.substring(3));
|
|
604
|
+
|
|
579
605
|
case "timestamp":
|
|
580
606
|
date = new Date(value);
|
|
581
607
|
timestamp = date.getTime();
|
|
@@ -598,6 +624,34 @@ function transform(value) {
|
|
|
598
624
|
throw new Error("unsupported locale or missing format (" + e.message + ")");
|
|
599
625
|
}
|
|
600
626
|
|
|
627
|
+
case "datetime":
|
|
628
|
+
date = new Date(value);
|
|
629
|
+
if (isNaN(date.getTime())) {
|
|
630
|
+
throw new Error("invalid date");
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
try {
|
|
634
|
+
locale = getLocaleOfDocument();
|
|
635
|
+
return date.toLocaleString(locale);
|
|
636
|
+
|
|
637
|
+
} catch (e) {
|
|
638
|
+
throw new Error("unsupported locale or missing format (" + e.message + ")");
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
case "date":
|
|
642
|
+
date = new Date(value);
|
|
643
|
+
if (isNaN(date.getTime())) {
|
|
644
|
+
throw new Error("invalid date");
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
try {
|
|
648
|
+
locale = getLocaleOfDocument();
|
|
649
|
+
return date.toLocaleDateString(locale);
|
|
650
|
+
|
|
651
|
+
} catch (e) {
|
|
652
|
+
throw new Error("unsupported locale or missing format (" + e.message + ")");
|
|
653
|
+
}
|
|
654
|
+
|
|
601
655
|
|
|
602
656
|
case "year":
|
|
603
657
|
date = new Date(value);
|
|
@@ -658,20 +712,6 @@ function transform(value) {
|
|
|
658
712
|
|
|
659
713
|
return date.getSeconds();
|
|
660
714
|
|
|
661
|
-
case "date":
|
|
662
|
-
date = new Date(value);
|
|
663
|
-
if (isNaN(date.getTime())) {
|
|
664
|
-
throw new Error("invalid date");
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
try {
|
|
668
|
-
locale = getLocaleOfDocument();
|
|
669
|
-
return date.toLocaleDateString(locale);
|
|
670
|
-
|
|
671
|
-
} catch (e) {
|
|
672
|
-
throw new Error("unsupported locale or missing format (" + e.message + ")");
|
|
673
|
-
}
|
|
674
|
-
|
|
675
715
|
case "i18n":
|
|
676
716
|
case "translation":
|
|
677
717
|
translations = getDocumentTranslations();
|
package/source/types/version.mjs
CHANGED
|
@@ -28,6 +28,10 @@ describe('Transformer', function () {
|
|
|
28
28
|
describe('Transformer.run()', function () {
|
|
29
29
|
|
|
30
30
|
[
|
|
31
|
+
['currency:1:2', "EUR14.25", "14,2 €"],
|
|
32
|
+
['currency', "EUR14.25", "14,25 €"],
|
|
33
|
+
['datetime', "2023-02-14 14:12:10", "14.2.2023, 14:12:10"],
|
|
34
|
+
['datetime', "2023-02-14 08:02:01", "14.2.2023, 08:02:01"],
|
|
31
35
|
['has-entries', {}, false],
|
|
32
36
|
['has-entries', {a:4}, true],
|
|
33
37
|
['has-entries', [], false],
|
package/test/cases/monster.mjs
CHANGED