@schukai/monster 3.17.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.17.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",
@@ -186,6 +186,33 @@ function transform(value) {
186
186
  case "tolowercase":
187
187
  validateString(value);
188
188
  return value.toLowerCase();
189
+
190
+ case "contains":
191
+ if (isString(value)) {
192
+ return value.includes(args[0]);
193
+ }
194
+
195
+ if (isArray(value)) {
196
+ return value.includes(args[0]);
197
+ }
198
+
199
+ if (isObject(value)) {
200
+ return value.hasOwnProperty(args[0]);
201
+ }
202
+
203
+ return false;
204
+
205
+ case "has-entries":
206
+ case "hasentries":
207
+ if (isObject(value)) {
208
+ return Object.keys(value).length > 0;
209
+ }
210
+
211
+ if (isArray(value)) {
212
+ return value.length > 0;
213
+ }
214
+
215
+ return false;
189
216
 
190
217
  case "isundefined":
191
218
  case "is-undefined":
@@ -549,6 +576,32 @@ function transform(value) {
549
576
 
550
577
  return map.get(value);
551
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
+
552
605
  case "timestamp":
553
606
  date = new Date(value);
554
607
  timestamp = date.getTime();
@@ -571,6 +624,34 @@ function transform(value) {
571
624
  throw new Error("unsupported locale or missing format (" + e.message + ")");
572
625
  }
573
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
+
574
655
 
575
656
  case "year":
576
657
  date = new Date(value);
@@ -631,20 +712,6 @@ function transform(value) {
631
712
 
632
713
  return date.getSeconds();
633
714
 
634
- case "date":
635
- date = new Date(value);
636
- if (isNaN(date.getTime())) {
637
- throw new Error("invalid date");
638
- }
639
-
640
- try {
641
- locale = getLocaleOfDocument();
642
- return date.toLocaleDateString(locale);
643
-
644
- } catch (e) {
645
- throw new Error("unsupported locale or missing format (" + e.message + ")");
646
- }
647
-
648
715
  case "i18n":
649
716
  case "translation":
650
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.17.0");
145
+ monsterVersion = new Version("3.19.0");
146
146
 
147
147
  return monsterVersion;
148
148
  }
@@ -28,6 +28,22 @@ 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"],
35
+ ['has-entries', {}, false],
36
+ ['has-entries', {a:4}, true],
37
+ ['has-entries', [], false],
38
+ ['has-entries', "", false],
39
+ ['has-entries', [1,2,3], true],
40
+ ['has-entries', [1], true],
41
+ ['has-entries', ["1"], true],
42
+ ['has-entries', [true], true],
43
+ ['contains:x', "asd wxd sdf", true],
44
+ ['contains:x', "asd wd sdf", false],
45
+ ['contains:b', ["a","b","c"], true],
46
+ ['contains:x', ["a","b","c"], false],
31
47
  ['isundefined', "a", false],
32
48
  ['isundefined', null, false],
33
49
  ['isundefined', undefined, true],
@@ -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.17.0")
10
+ monsterVersion = new Version("3.19.0")
11
11
 
12
12
  let m = getMonsterVersion();
13
13