@schukai/monster 3.18.0 → 3.19.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "3.18.0",
3
+ "version": "3.19.0",
4
4
  "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
5
5
  "keywords": [
6
6
  "framework",
@@ -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();
@@ -142,7 +142,7 @@ function getMonsterVersion() {
142
142
  }
143
143
 
144
144
  /** don't touch, replaced by make with package.json version */
145
- monsterVersion = new Version("3.18.0");
145
+ monsterVersion = new Version("3.19.0");
146
146
 
147
147
  return monsterVersion;
148
148
  }
@@ -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],
@@ -7,7 +7,7 @@ describe('Monster', function () {
7
7
  let monsterVersion
8
8
 
9
9
  /** don´t touch, replaced by make with package.json version */
10
- monsterVersion = new Version("3.18.0")
10
+ monsterVersion = new Version("3.19.0")
11
11
 
12
12
  let m = getMonsterVersion();
13
13