@schukai/monster 3.16.1 → 3.18.0
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -17,6 +17,7 @@ import {
|
|
17
17
|
validateObject,
|
18
18
|
validatePrimitive,
|
19
19
|
validateString,
|
20
|
+
validateBoolean,
|
20
21
|
} from "../types/validate.mjs";
|
21
22
|
import {clone} from "../util/clone.mjs";
|
22
23
|
import {Pathfinder} from "./pathfinder.mjs";
|
@@ -185,6 +186,69 @@ function transform(value) {
|
|
185
186
|
case "tolowercase":
|
186
187
|
validateString(value);
|
187
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;
|
216
|
+
|
217
|
+
case "isundefined":
|
218
|
+
case "is-undefined":
|
219
|
+
return value === undefined;
|
220
|
+
|
221
|
+
case "isnull":
|
222
|
+
case "is-null":
|
223
|
+
return value === null;
|
224
|
+
|
225
|
+
case "isset":
|
226
|
+
case "is-set":
|
227
|
+
return value !== undefined && value !== null;
|
228
|
+
|
229
|
+
case "isnumber":
|
230
|
+
case "is-number":
|
231
|
+
return isPrimitive(value) && !isNaN(value);
|
232
|
+
|
233
|
+
case "isinteger":
|
234
|
+
case "is-integer":
|
235
|
+
return isPrimitive(value) && !isNaN(value) && value % 1 === 0;
|
236
|
+
|
237
|
+
case "isfloat":
|
238
|
+
case "is-float":
|
239
|
+
return isPrimitive(value) && !isNaN(value) && value % 1 !== 0;
|
240
|
+
|
241
|
+
case "isobject":
|
242
|
+
case "is-object":
|
243
|
+
return isObject(value);
|
244
|
+
|
245
|
+
case "isarray":
|
246
|
+
case "is-array":
|
247
|
+
return Array.isArray(value);
|
248
|
+
|
249
|
+
case "not":
|
250
|
+
validateBoolean(value);
|
251
|
+
return !value;
|
188
252
|
|
189
253
|
case "toupper":
|
190
254
|
case "strtoupper":
|
@@ -497,7 +561,7 @@ function transform(value) {
|
|
497
561
|
|
498
562
|
throw new Error("type not supported");
|
499
563
|
|
500
|
-
|
564
|
+
|
501
565
|
case "map":
|
502
566
|
map = new Map();
|
503
567
|
while (args.length > 0) {
|
@@ -505,13 +569,13 @@ function transform(value) {
|
|
505
569
|
if (keyValue === undefined) {
|
506
570
|
throw new Error("missing key parameter");
|
507
571
|
}
|
508
|
-
|
572
|
+
|
509
573
|
keyValue = keyValue.split("=");
|
510
574
|
map.set(keyValue[0], keyValue[1]);
|
511
575
|
}
|
512
|
-
|
576
|
+
|
513
577
|
return map.get(value);
|
514
|
-
|
578
|
+
|
515
579
|
case "timestamp":
|
516
580
|
date = new Date(value);
|
517
581
|
timestamp = date.getTime();
|
package/source/types/version.mjs
CHANGED
@@ -24,9 +24,43 @@ describe('Transformer', function () {
|
|
24
24
|
|
25
25
|
});
|
26
26
|
|
27
|
+
|
27
28
|
describe('Transformer.run()', function () {
|
28
29
|
|
29
30
|
[
|
31
|
+
['has-entries', {}, false],
|
32
|
+
['has-entries', {a:4}, true],
|
33
|
+
['has-entries', [], false],
|
34
|
+
['has-entries', "", false],
|
35
|
+
['has-entries', [1,2,3], true],
|
36
|
+
['has-entries', [1], true],
|
37
|
+
['has-entries', ["1"], true],
|
38
|
+
['has-entries', [true], true],
|
39
|
+
['contains:x', "asd wxd sdf", true],
|
40
|
+
['contains:x', "asd wd sdf", false],
|
41
|
+
['contains:b', ["a","b","c"], true],
|
42
|
+
['contains:x', ["a","b","c"], false],
|
43
|
+
['isundefined', "a", false],
|
44
|
+
['isundefined', null, false],
|
45
|
+
['isundefined', undefined, true],
|
46
|
+
['isnull', "a", false],
|
47
|
+
['isnull', null, true],
|
48
|
+
['isset', null, false],
|
49
|
+
['isset', undefined, false],
|
50
|
+
['isset', "", true],
|
51
|
+
['isnumber', "a", false],
|
52
|
+
['isnumber', 4, true],
|
53
|
+
['isnumber', 4.5, true],
|
54
|
+
['isinteger', 4.5, false],
|
55
|
+
['isinteger', 4, true],
|
56
|
+
['isfloat', 5.6, true],
|
57
|
+
['isfloat', 5, false],
|
58
|
+
['isobject', 4, false],
|
59
|
+
['isobject', {}, true],
|
60
|
+
['isarray', [{}], true],
|
61
|
+
['isarray', "a", false],
|
62
|
+
['not', true, false],
|
63
|
+
['not', false, true],
|
30
64
|
['map:a=4:b=5:c=6', "a", "4"],
|
31
65
|
['date', "2023-02-14", "14.2.2023"],
|
32
66
|
['year', "2023-02-14", 2023],
|
package/test/cases/monster.mjs
CHANGED