@schukai/monster 1.22.0 → 1.26.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG +56 -0
- package/README.md +4 -4
- package/dist/modules/constants.js +2 -2
- package/dist/modules/constraints/abstract.js +1 -1
- package/dist/modules/constraints/abstractoperator.js +1 -1
- package/dist/modules/constraints/andoperator.js +1 -1
- package/dist/modules/constraints/invalid.js +1 -1
- package/dist/modules/constraints/isarray.js +1 -1
- package/dist/modules/constraints/isobject.js +1 -1
- package/dist/modules/constraints/namespace.js +1 -1
- package/dist/modules/constraints/oroperator.js +1 -1
- package/dist/modules/constraints/valid.js +1 -1
- package/dist/modules/data/buildmap.js +2 -2
- package/dist/modules/data/buildtree.js +2 -0
- package/dist/modules/data/datasource/namespace.js +1 -1
- package/dist/modules/data/datasource/restapi/writeerror.js +2 -0
- package/dist/modules/data/datasource/restapi.js +2 -2
- package/dist/modules/data/datasource/storage/localstorage.js +2 -2
- package/dist/modules/data/datasource/storage/namespace.js +1 -1
- package/dist/modules/data/datasource/storage/sessionstorage.js +2 -2
- package/dist/modules/data/datasource/storage.js +2 -2
- package/dist/modules/data/datasource.js +2 -2
- package/dist/modules/data/diff.js +2 -2
- package/dist/modules/data/extend.js +1 -1
- package/dist/modules/data/namespace.js +1 -1
- package/dist/modules/data/pathfinder.js +2 -2
- package/dist/modules/data/pipe.js +1 -1
- package/dist/modules/data/transformer.js +2 -2
- package/dist/modules/dom/assembler.js +1 -1
- package/dist/modules/dom/attributes.js +1 -1
- package/dist/modules/dom/constants.js +2 -2
- package/dist/modules/dom/customcontrol.js +2 -2
- package/dist/modules/dom/customelement.js +2 -2
- package/dist/modules/dom/events.js +1 -1
- package/dist/modules/dom/focusmanager.js +2 -0
- package/dist/modules/dom/locale.js +1 -1
- package/dist/modules/dom/namespace.js +1 -1
- package/dist/modules/dom/resource/data.js +2 -0
- package/dist/modules/dom/resource/link/stylesheet.js +2 -0
- package/dist/modules/dom/resource/link.js +2 -0
- package/dist/modules/dom/resource/script.js +2 -0
- package/dist/modules/dom/resource.js +2 -0
- package/dist/modules/dom/resourcemanager.js +2 -0
- package/dist/modules/dom/template.js +1 -1
- package/dist/modules/dom/theme.js +1 -1
- package/dist/modules/dom/updater.js +2 -2
- package/dist/modules/dom/util.js +1 -1
- package/dist/modules/dom/worker/factory.js +2 -0
- package/dist/modules/i18n/formatter.js +2 -0
- package/dist/modules/i18n/locale.js +1 -1
- package/dist/modules/i18n/namespace.js +1 -1
- package/dist/modules/i18n/provider.js +1 -1
- package/dist/modules/i18n/providers/fetch.js +2 -2
- package/dist/modules/i18n/providers/namespace.js +1 -1
- package/dist/modules/i18n/translations.js +1 -1
- package/dist/modules/logging/handler/console.js +1 -1
- package/dist/modules/logging/handler/namespace.js +1 -1
- package/dist/modules/logging/handler.js +1 -1
- package/dist/modules/logging/logentry.js +1 -1
- package/dist/modules/logging/logger.js +1 -1
- package/dist/modules/logging/namespace.js +1 -1
- package/dist/modules/math/namespace.js +1 -1
- package/dist/modules/math/random.js +2 -2
- package/dist/modules/monster.js +1 -1
- package/dist/modules/namespace.js +1 -1
- package/dist/modules/text/formatter.js +2 -2
- package/dist/modules/text/namespace.js +1 -1
- package/dist/modules/types/base.js +1 -1
- package/dist/modules/types/basewithoptions.js +2 -2
- package/dist/modules/types/binary.js +1 -1
- package/dist/modules/types/dataurl.js +1 -1
- package/dist/modules/types/global.js +1 -1
- package/dist/modules/types/id.js +1 -1
- package/dist/modules/types/is.js +2 -2
- package/dist/modules/types/mediatype.js +1 -1
- package/dist/modules/types/namespace.js +1 -1
- package/dist/modules/types/node.js +2 -0
- package/dist/modules/types/nodelist.js +2 -0
- package/dist/modules/types/noderecursiveiterator.js +2 -0
- package/dist/modules/types/observer.js +1 -1
- package/dist/modules/types/observerlist.js +2 -2
- package/dist/modules/types/proxyobserver.js +2 -2
- package/dist/modules/types/queue.js +1 -1
- package/dist/modules/types/randomid.js +1 -1
- package/dist/modules/types/regex.js +2 -0
- package/dist/modules/types/stack.js +1 -1
- package/dist/modules/types/tokenlist.js +2 -2
- package/dist/modules/types/typeof.js +1 -1
- package/dist/modules/types/uniquequeue.js +1 -1
- package/dist/modules/types/uuid.js +2 -0
- package/dist/modules/types/validate.js +1 -1
- package/dist/modules/types/version.js +2 -2
- package/dist/modules/util/clone.js +2 -2
- package/dist/modules/util/comparator.js +2 -2
- package/dist/modules/util/freeze.js +1 -1
- package/dist/modules/util/namespace.js +1 -1
- package/dist/modules/util/processing.js +2 -2
- package/dist/modules/util/trimspaces.js +2 -0
- package/dist/monster.dev.js +1838 -792
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +2 -2
- package/package.json +13 -2
- package/source/constants.js +16 -7
- package/source/constraints/abstract.js +5 -0
- package/source/constraints/abstractoperator.js +5 -0
- package/source/constraints/andoperator.js +10 -5
- package/source/constraints/invalid.js +8 -3
- package/source/constraints/isarray.js +9 -4
- package/source/constraints/isobject.js +8 -3
- package/source/constraints/oroperator.js +10 -5
- package/source/constraints/valid.js +8 -3
- package/source/data/buildmap.js +27 -11
- package/source/data/buildtree.js +95 -0
- package/source/data/datasource/restapi/writeerror.js +49 -0
- package/source/data/datasource/restapi.js +95 -11
- package/source/data/datasource/storage/localstorage.js +15 -8
- package/source/data/datasource/storage/sessionstorage.js +16 -12
- package/source/data/datasource/storage.js +16 -7
- package/source/data/datasource.js +60 -16
- package/source/data/diff.js +8 -8
- package/source/data/extend.js +5 -5
- package/source/data/pathfinder.js +12 -6
- package/source/data/pipe.js +6 -5
- package/source/data/transformer.js +131 -24
- package/source/dom/assembler.js +2 -2
- package/source/dom/attributes.js +24 -24
- package/source/dom/constants.js +305 -12
- package/source/dom/customcontrol.js +40 -19
- package/source/dom/customelement.js +182 -102
- package/source/dom/events.js +6 -6
- package/source/dom/focusmanager.js +250 -0
- package/source/dom/locale.js +10 -5
- package/source/dom/resource/data.js +170 -0
- package/source/dom/resource/link/stylesheet.js +54 -0
- package/source/dom/resource/link.js +125 -0
- package/source/dom/resource/script.js +112 -0
- package/source/dom/resource.js +268 -0
- package/source/dom/resourcemanager.js +214 -0
- package/source/dom/template.js +40 -10
- package/source/dom/theme.js +3 -3
- package/source/dom/updater.js +115 -39
- package/source/dom/util.js +6 -6
- package/source/dom/worker/factory.js +134 -0
- package/source/i18n/formatter.js +140 -0
- package/source/i18n/locale.js +10 -8
- package/source/i18n/provider.js +4 -4
- package/source/i18n/providers/fetch.js +24 -14
- package/source/i18n/translations.js +20 -10
- package/source/logging/handler/console.js +2 -2
- package/source/logging/handler.js +2 -2
- package/source/logging/logentry.js +2 -2
- package/source/logging/logger.js +4 -4
- package/source/math/random.js +11 -5
- package/source/namespace.js +1 -1
- package/source/text/formatter.js +244 -27
- package/source/types/base.js +4 -4
- package/source/types/basewithoptions.js +10 -15
- package/source/types/binary.js +8 -8
- package/source/types/dataurl.js +6 -6
- package/source/types/global.js +9 -7
- package/source/types/id.js +6 -3
- package/source/types/is.js +103 -85
- package/source/types/mediatype.js +4 -4
- package/source/types/node.js +179 -0
- package/source/types/nodelist.js +125 -0
- package/source/types/noderecursiveiterator.js +126 -0
- package/source/types/observer.js +3 -3
- package/source/types/observerlist.js +3 -3
- package/source/types/proxyobserver.js +24 -7
- package/source/types/queue.js +6 -6
- package/source/types/randomid.js +2 -2
- package/source/types/regex.js +49 -0
- package/source/types/stack.js +2 -2
- package/source/types/tokenlist.js +8 -9
- package/source/types/typeof.js +3 -3
- package/source/types/uniquequeue.js +4 -4
- package/source/types/uuid.js +102 -0
- package/source/types/validate.js +20 -20
- package/source/types/version.js +6 -6
- package/source/util/clone.js +5 -6
- package/source/util/comparator.js +5 -5
- package/source/util/freeze.js +5 -5
- package/source/util/processing.js +33 -36
- package/source/util/trimspaces.js +85 -0
- package/test/cases/data/buildtree.js +149 -0
- package/test/cases/data/datasource/restapi.js +1 -1
- package/test/cases/data/datasource.js +4 -4
- package/test/cases/data/diff.js +4 -4
- package/test/cases/data/pathfinder.js +18 -9
- package/test/cases/data/pipe.js +26 -2
- package/test/cases/data/transformer.js +41 -10
- package/test/cases/dom/attributes.js +18 -14
- package/test/cases/dom/customcontrol.js +6 -5
- package/test/cases/dom/customelement.js +25 -26
- package/test/cases/dom/focusmanager.js +111 -0
- package/test/cases/dom/locale.js +1 -4
- package/test/cases/dom/resource/data.js +129 -0
- package/test/cases/dom/resource/link/stylesheet.js +101 -0
- package/test/cases/dom/resource/link.js +101 -0
- package/test/cases/dom/resource/script.js +115 -0
- package/test/cases/dom/resourcemanager.js +118 -0
- package/test/cases/dom/updater.js +42 -19
- package/test/cases/dom/worker/factory.js +63 -0
- package/test/cases/i18n/formatter.js +66 -0
- package/test/cases/monster.js +1 -1
- package/test/cases/text/formatter.js +71 -8
- package/test/cases/types/node.js +196 -0
- package/test/cases/types/nodelist.js +64 -0
- package/test/cases/types/noderecursiveiterator.js +54 -0
- package/test/cases/types/proxyobserver.js +55 -11
- package/test/cases/types/regex.js +32 -0
- package/test/cases/types/uuid.js +42 -0
- package/test/cases/util/freeze.js +30 -4
- package/test/cases/util/trimspaces.js +24 -0
- package/test/util/cleanupdom.js +48 -0
- package/test/util/jsdom.js +22 -9
- package/test/web/import.js +15 -0
- package/test/web/monster-dev.html +3 -3
- package/test/web/monster.html +2 -2
- package/test/web/test.html +3 -3
- package/test/web/tests.js +7 -7
package/source/data/pipe.js
CHANGED
@@ -19,8 +19,8 @@ const DELIMITER = '|';
|
|
19
19
|
*
|
20
20
|
* ```
|
21
21
|
* <script type="module">
|
22
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
23
|
-
*
|
22
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
23
|
+
* new Monster.Data.Pipe()
|
24
24
|
* </script>
|
25
25
|
* ```
|
26
26
|
*
|
@@ -28,8 +28,8 @@ const DELIMITER = '|';
|
|
28
28
|
*
|
29
29
|
* ```
|
30
30
|
* <script type="module">
|
31
|
-
* import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
32
|
-
*
|
31
|
+
* import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/data/pipe.js';
|
32
|
+
* new Pipe()
|
33
33
|
* </script>
|
34
34
|
* ```
|
35
35
|
*
|
@@ -39,7 +39,7 @@ const DELIMITER = '|';
|
|
39
39
|
* the word is then converted to uppercase letters and a prefix Hello is added. the two backslash safe the space char.
|
40
40
|
*
|
41
41
|
* @example
|
42
|
-
* import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
42
|
+
* import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/data/pipe.js';
|
43
43
|
*
|
44
44
|
* let obj = {
|
45
45
|
* a: {
|
@@ -68,6 +68,7 @@ class Pipe extends Base {
|
|
68
68
|
constructor(pipe) {
|
69
69
|
super();
|
70
70
|
validateString(pipe);
|
71
|
+
|
71
72
|
this.pipe = pipe.split(DELIMITER).map((v) => {
|
72
73
|
return new Transformer(v);
|
73
74
|
});
|
@@ -5,7 +5,7 @@
|
|
5
5
|
*/
|
6
6
|
import {assignToNamespace, Monster} from '../namespace.js';
|
7
7
|
import {Base} from '../types/base.js';
|
8
|
-
import {getGlobal} from "../types/global.js";
|
8
|
+
import {getGlobal, getGlobalObject} from "../types/global.js";
|
9
9
|
import {ID} from '../types/id.js';
|
10
10
|
import {isArray, isObject, isString} from '../types/is.js';
|
11
11
|
import {
|
@@ -25,8 +25,8 @@ import {Pathfinder} from "./pathfinder.js";
|
|
25
25
|
*
|
26
26
|
* ```
|
27
27
|
* <script type="module">
|
28
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
29
|
-
*
|
28
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
29
|
+
* new Monster.Data.Transformer()
|
30
30
|
* </script>
|
31
31
|
* ```
|
32
32
|
*
|
@@ -34,12 +34,12 @@ import {Pathfinder} from "./pathfinder.js";
|
|
34
34
|
*
|
35
35
|
* ```
|
36
36
|
* <script type="module">
|
37
|
-
* import {Transformer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
38
|
-
*
|
37
|
+
* import {Transformer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/data/transformer.js';
|
38
|
+
* new Transformer()
|
39
39
|
* </script>
|
40
40
|
* ```
|
41
41
|
*
|
42
|
-
* A simple example is the conversion of all characters to lowercase. for this purpose the command tolower must be used.
|
42
|
+
* A simple example is the conversion of all characters to lowercase. for this purpose the command `tolower` must be used.
|
43
43
|
*
|
44
44
|
* ```
|
45
45
|
* let t = new Transformer('tolower').run('ABC'); // ↦ abc
|
@@ -51,16 +51,23 @@ import {Pathfinder} from "./pathfinder.js";
|
|
51
51
|
*
|
52
52
|
* | command | parameter | alias | description |
|
53
53
|
* |:-------------|:---------------------------|:------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
54
|
-
* | base64
|
54
|
+
* | to-base64 | | base64, btob | Converts the value to base64 |
|
55
|
+
* | from-base64 | | atob | Converts the value from base64 |
|
55
56
|
* | call | function:param1:param2:... | | Calling a callback function. The function can be defined in three places: either globally, in the context `addCallback` or in the passed object |
|
56
|
-
* | default |
|
57
|
+
* | default | value:type | ?? | If the value is undefined the first argument is returned, otherwise the value. The third optional parameter specifies the desired type. If no type is specified, string is used. Valid types are bool, string, int, float, undefined and object. An object default value must be specified as a base64 encoded json string. (since 1.12.0) |
|
58
|
+
* | debug | | | the passed value is output (console) and returned |
|
57
59
|
* | empty | | | Return empty String "" |
|
60
|
+
* | first-key | default | | Can be applied to objects and returns the value of the first key. All keys of the object are fetched and sorted. (since 1.23.0) |
|
58
61
|
* | fromjson | | | Type conversion from a JSON string (since 1.12.0) |
|
59
|
-
* | if | statement1:statement2 | ? | Is the ternary operator, the first parameter is the valid statement, the second is the false part. To use the current value in the queue, you can set the value keyword. On the other hand, if you want to have the static string "value", you have to put one backslash \\ in front of it and write value. the follow values are true: 'on', true, 'true' |
|
62
|
+
* | if | statement1:statement2 | ? | Is the ternary operator, the first parameter is the valid statement, the second is the false part. To use the current value in the queue, you can set the value keyword. On the other hand, if you want to have the static string "value", you have to put one backslash \\ in front of it and write value. the follow values are true: 'on', true, 'true'. If you want to have a space, you also have to write \\ in front of the space. |
|
60
63
|
* | index | key:default | property, key | Fetches a value from an object, an array, a map or a set |
|
64
|
+
* | last-key | default | | Can be applied to objects and returns the value of the last key. All keys of the object are fetched and sorted. (since 1.23.0) |
|
61
65
|
* | length | | count | Length of the string or entries of an array or object |
|
62
66
|
* | nop | | | Do nothing |
|
67
|
+
* | nth-key | index:default | | Can be applied to objects and returns the value of the nth key. All keys of the object are fetched and sorted. (since 1.23.0) |
|
68
|
+
* | nth-last-key | index:default | | Can be applied to objects and returns the value of the nth key from behind. All keys of the object are fetched and sorted. (since 1.23.0) |
|
63
69
|
* | path | path | | The access to an object is done via a Pathfinder object |
|
70
|
+
* | path-exists | path | | Check if the specified path is available in the value (since 1.24.0) |
|
64
71
|
* | plaintext | | plain | All HTML tags are removed (*) |
|
65
72
|
* | prefix | text | | Adds a prefix |
|
66
73
|
* | rawurlencode | | | URL coding |
|
@@ -70,13 +77,13 @@ import {Pathfinder} from "./pathfinder.js";
|
|
70
77
|
* | tointeger | | | Type conversion to an integer value |
|
71
78
|
* | tojson | | | Type conversion to a JSON string (since 1.8.0) |
|
72
79
|
* | tolower | | strtolower, tolowercase | The input value is converted to lowercase letters |
|
73
|
-
* | tostring | | | Type conversion to a string
|
80
|
+
* | tostring | | | Type conversion to a string. |
|
74
81
|
* | toupper | | strtoupper, touppercase | The input value is converted to uppercase letters |
|
75
82
|
* | trim | | | Remove spaces at the beginning and end |
|
76
83
|
* | ucfirst | | | First character large |
|
77
84
|
* | ucwords | | | Any word beginning large |
|
78
85
|
* | undefined | | | Return undefined |
|
79
|
-
* | uniqid | | | Creates a string with a unique value (**)
|
86
|
+
* | uniqid | | | Creates a string with a unique value (**)
|
80
87
|
*
|
81
88
|
* (*) for this functionality the extension [jsdom](https://www.npmjs.com/package/jsdom) must be loaded in the nodejs context.
|
82
89
|
*
|
@@ -113,7 +120,7 @@ import {Pathfinder} from "./pathfinder.js";
|
|
113
120
|
*
|
114
121
|
* @example
|
115
122
|
*
|
116
|
-
* import {Transformer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
123
|
+
* import {Transformer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/data/transformer.js';
|
117
124
|
*
|
118
125
|
* const transformer = new Transformer("tolower")
|
119
126
|
*
|
@@ -134,8 +141,6 @@ class Transformer extends Base {
|
|
134
141
|
*/
|
135
142
|
constructor(definition) {
|
136
143
|
super();
|
137
|
-
validateString(definition);
|
138
|
-
|
139
144
|
this.args = disassemble(definition);
|
140
145
|
this.command = this.args.shift()
|
141
146
|
this.callbacks = new Map();
|
@@ -196,7 +201,7 @@ function disassemble(command) {
|
|
196
201
|
let placeholder = new Map;
|
197
202
|
const regex = /((?<pattern>\\(?<char>.)){1})/mig;
|
198
203
|
|
199
|
-
// The separator for args must be
|
204
|
+
// The separator for args must be escaped
|
200
205
|
// undefined string which should not occur normally and is also not a regex
|
201
206
|
let result = command.matchAll(regex)
|
202
207
|
|
@@ -256,11 +261,14 @@ function convertToString(value) {
|
|
256
261
|
* @throws {Error} unknown command
|
257
262
|
* @throws {TypeError} unsupported type
|
258
263
|
* @throws {Error} type not supported
|
264
|
+
* @throws {Error} missing key parameter
|
259
265
|
*/
|
260
266
|
function transform(value) {
|
261
267
|
|
268
|
+
const console = getGlobalObject('console');
|
269
|
+
|
262
270
|
let args = clone(this.args);
|
263
|
-
let key
|
271
|
+
let key, defaultValue;
|
264
272
|
|
265
273
|
switch (this.command) {
|
266
274
|
|
@@ -386,9 +394,14 @@ function transform(value) {
|
|
386
394
|
|
387
395
|
throw new TypeError("unsupported type " + typeof value);
|
388
396
|
|
397
|
+
case 'to-base64':
|
398
|
+
case 'btoa':
|
389
399
|
case 'base64':
|
390
|
-
convertToString(value);
|
391
|
-
|
400
|
+
return btoa(convertToString(value));
|
401
|
+
|
402
|
+
case 'atob':
|
403
|
+
case 'from-base64':
|
404
|
+
return atob(convertToString(value));
|
392
405
|
|
393
406
|
case 'empty':
|
394
407
|
return '';
|
@@ -396,6 +409,14 @@ function transform(value) {
|
|
396
409
|
case 'undefined':
|
397
410
|
return undefined;
|
398
411
|
|
412
|
+
case 'debug':
|
413
|
+
|
414
|
+
if (isObject(console)) {
|
415
|
+
console.log(value);
|
416
|
+
}
|
417
|
+
|
418
|
+
return value;
|
419
|
+
|
399
420
|
case 'prefix':
|
400
421
|
validateString(value);
|
401
422
|
let prefix = args?.[0];
|
@@ -409,12 +430,52 @@ function transform(value) {
|
|
409
430
|
case 'uniqid':
|
410
431
|
return (new ID()).toString();
|
411
432
|
|
433
|
+
case 'first-key':
|
434
|
+
case 'last-key':
|
435
|
+
case 'nth-last-key':
|
436
|
+
case 'nth-key':
|
437
|
+
|
438
|
+
if (!isObject(value)) {
|
439
|
+
throw new Error("type not supported")
|
440
|
+
}
|
441
|
+
|
442
|
+
const keys = Object.keys(value).sort()
|
443
|
+
|
444
|
+
if (this.command === 'first-key') {
|
445
|
+
key = 0;
|
446
|
+
} else if (this.command === 'last-key') {
|
447
|
+
key = keys.length - 1;
|
448
|
+
} else {
|
449
|
+
|
450
|
+
key = validateInteger(parseInt(args.shift()));
|
451
|
+
|
452
|
+
if (this.command === 'nth-last-key') {
|
453
|
+
key = keys.length - key - 1;
|
454
|
+
}
|
455
|
+
}
|
456
|
+
|
457
|
+
defaultValue = (args.shift() || '');
|
458
|
+
|
459
|
+
let useKey = keys?.[key];
|
460
|
+
|
461
|
+
if (value?.[useKey]) {
|
462
|
+
return value?.[useKey];
|
463
|
+
}
|
464
|
+
|
465
|
+
return defaultValue;
|
466
|
+
|
467
|
+
|
412
468
|
case 'key':
|
413
469
|
case 'property':
|
414
470
|
case 'index':
|
415
471
|
|
416
|
-
key =
|
417
|
-
|
472
|
+
key = args.shift() || undefined;
|
473
|
+
|
474
|
+
if (key === undefined) {
|
475
|
+
throw new Error("missing key parameter")
|
476
|
+
}
|
477
|
+
|
478
|
+
defaultValue = (args.shift() || undefined);
|
418
479
|
|
419
480
|
if (value instanceof Map) {
|
420
481
|
if (!value.has(key)) {
|
@@ -434,10 +495,29 @@ function transform(value) {
|
|
434
495
|
|
435
496
|
throw new Error("type not supported")
|
436
497
|
|
498
|
+
case 'path-exists':
|
499
|
+
|
500
|
+
key = args.shift();
|
501
|
+
if (key === undefined) {
|
502
|
+
throw new Error("missing key parameter")
|
503
|
+
}
|
504
|
+
|
505
|
+
return new Pathfinder(value).exists(key);
|
506
|
+
|
437
507
|
case 'path':
|
438
508
|
|
439
|
-
key =
|
440
|
-
|
509
|
+
key = args.shift();
|
510
|
+
if (key === undefined) {
|
511
|
+
throw new Error("missing key parameter")
|
512
|
+
}
|
513
|
+
|
514
|
+
let pf = new Pathfinder(value);
|
515
|
+
|
516
|
+
if (!pf.exists(key)) {
|
517
|
+
return undefined;
|
518
|
+
}
|
519
|
+
|
520
|
+
return pf.getVia(key);
|
441
521
|
|
442
522
|
|
443
523
|
case 'substring':
|
@@ -452,11 +532,38 @@ function transform(value) {
|
|
452
532
|
case 'nop':
|
453
533
|
return value;
|
454
534
|
|
535
|
+
case '??':
|
455
536
|
case 'default':
|
456
|
-
if (value !== undefined) {
|
537
|
+
if (value !== undefined && value !== null) {
|
457
538
|
return value;
|
458
539
|
}
|
459
|
-
|
540
|
+
|
541
|
+
defaultValue = args.shift();
|
542
|
+
let defaultType = args.shift();
|
543
|
+
if (defaultType === undefined) {
|
544
|
+
defaultType = 'string';
|
545
|
+
}
|
546
|
+
|
547
|
+
switch (defaultType) {
|
548
|
+
case 'int':
|
549
|
+
case 'integer':
|
550
|
+
return parseInt(defaultValue);
|
551
|
+
case 'float':
|
552
|
+
return parseFloat(defaultValue);
|
553
|
+
case 'undefined':
|
554
|
+
return undefined
|
555
|
+
case 'bool':
|
556
|
+
case 'boolean':
|
557
|
+
defaultValue = defaultValue.toLowerCase()
|
558
|
+
return ((defaultValue !== 'undefined' && defaultValue !== '' && defaultValue !== 'off' && defaultValue !== 'false' && defaultValue !== 'false') || defaultValue === 'on' || defaultValue === 'true' || defaultValue === 'true');
|
559
|
+
case 'string':
|
560
|
+
return "" + defaultValue;
|
561
|
+
case "object":
|
562
|
+
return JSON.parse(atob(defaultValue));
|
563
|
+
}
|
564
|
+
|
565
|
+
throw new Error("type not supported")
|
566
|
+
|
460
567
|
|
461
568
|
default:
|
462
569
|
throw new Error("unknown command " + this.command)
|
package/source/dom/assembler.js
CHANGED
@@ -23,7 +23,7 @@ const ATTRIBUTEPREFIX = "data-monster-";
|
|
23
23
|
*
|
24
24
|
* ```
|
25
25
|
* <script type="module">
|
26
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
26
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
27
27
|
* console.log(new Monster.DOM.Assembler())
|
28
28
|
* </script>
|
29
29
|
* ```
|
@@ -32,7 +32,7 @@ const ATTRIBUTEPREFIX = "data-monster-";
|
|
32
32
|
*
|
33
33
|
* ```
|
34
34
|
* <script type="module">
|
35
|
-
* import {Assembler} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
35
|
+
* import {Assembler} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/assembler.js';
|
36
36
|
* console.log(new Assembler())
|
37
37
|
* </script>
|
38
38
|
* ```
|
package/source/dom/attributes.js
CHANGED
@@ -20,7 +20,7 @@ import {ATTRIBUTE_OBJECTLINK} from "./constants.js";
|
|
20
20
|
*
|
21
21
|
* ```
|
22
22
|
* <script type="module">
|
23
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
23
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
24
24
|
* console.log(Monster.DOM.findClosestObjectLink())
|
25
25
|
* </script>
|
26
26
|
* ```
|
@@ -29,7 +29,7 @@ import {ATTRIBUTE_OBJECTLINK} from "./constants.js";
|
|
29
29
|
*
|
30
30
|
* ```
|
31
31
|
* <script type="module">
|
32
|
-
* import {getUpdaterFromNode} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
32
|
+
* import {getUpdaterFromNode} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/updater.js';
|
33
33
|
* console.log(findClosestObjectLink())
|
34
34
|
* </script>
|
35
35
|
* ```
|
@@ -50,7 +50,7 @@ function findClosestObjectLink(element) {
|
|
50
50
|
*
|
51
51
|
* ```
|
52
52
|
* <script type="module">
|
53
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
53
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
54
54
|
* Monster.DOM.addToObjectLink();
|
55
55
|
* </script>
|
56
56
|
* ```
|
@@ -59,7 +59,7 @@ function findClosestObjectLink(element) {
|
|
59
59
|
*
|
60
60
|
* ```
|
61
61
|
* <script type="module">
|
62
|
-
* import {addToObjectLink} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
62
|
+
* import {addToObjectLink} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/attributes.js';
|
63
63
|
* addToObjectLink();
|
64
64
|
* </script>
|
65
65
|
* ```
|
@@ -92,7 +92,7 @@ function addToObjectLink(element, symbol, object) {
|
|
92
92
|
*
|
93
93
|
* ```
|
94
94
|
* <script type="module">
|
95
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
95
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
96
96
|
* Monster.DOM.removeObjectLink();
|
97
97
|
* </script>
|
98
98
|
* ```
|
@@ -101,7 +101,7 @@ function addToObjectLink(element, symbol, object) {
|
|
101
101
|
*
|
102
102
|
* ```
|
103
103
|
* <script type="module">
|
104
|
-
* import {removeObjectLink} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
104
|
+
* import {removeObjectLink} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/attributes.js';
|
105
105
|
* removeObjectLink();
|
106
106
|
* </script>
|
107
107
|
* ```
|
@@ -134,7 +134,7 @@ function removeObjectLink(element, symbol) {
|
|
134
134
|
*
|
135
135
|
* ```
|
136
136
|
* <script type="module">
|
137
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
137
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
138
138
|
* Monster.DOM.hasObjectLink();
|
139
139
|
* </script>
|
140
140
|
* ```
|
@@ -143,7 +143,7 @@ function removeObjectLink(element, symbol) {
|
|
143
143
|
*
|
144
144
|
* ```
|
145
145
|
* <script type="module">
|
146
|
-
* import {hasObjectLink} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
146
|
+
* import {hasObjectLink} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/attributes.js';
|
147
147
|
* hasObjectLink();
|
148
148
|
* </script>
|
149
149
|
* ```
|
@@ -180,7 +180,7 @@ function hasObjectLink(element, symbol) {
|
|
180
180
|
*
|
181
181
|
* ```
|
182
182
|
* <script type="module">
|
183
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
183
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
184
184
|
* Monster.DOM.getLinkedObjects();
|
185
185
|
* </script>
|
186
186
|
* ```
|
@@ -189,7 +189,7 @@ function hasObjectLink(element, symbol) {
|
|
189
189
|
*
|
190
190
|
* ```
|
191
191
|
* <script type="module">
|
192
|
-
* import {getLinkedObjects} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
192
|
+
* import {getLinkedObjects} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/attributes.js';
|
193
193
|
* getLinkedObjects();
|
194
194
|
* </script>
|
195
195
|
* ```
|
@@ -225,7 +225,7 @@ function getLinkedObjects(element, symbol) {
|
|
225
225
|
*
|
226
226
|
* ```
|
227
227
|
* <script type="module">
|
228
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
228
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
229
229
|
* Monster.DOM.toggleAttributeToken();
|
230
230
|
* </script>
|
231
231
|
* ```
|
@@ -234,7 +234,7 @@ function getLinkedObjects(element, symbol) {
|
|
234
234
|
*
|
235
235
|
* ```
|
236
236
|
* <script type="module">
|
237
|
-
* import {toggleAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
237
|
+
* import {toggleAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/attributes.js';
|
238
238
|
* toggleAttributeToken();
|
239
239
|
* </script>
|
240
240
|
* ```
|
@@ -269,7 +269,7 @@ function toggleAttributeToken(element, key, token) {
|
|
269
269
|
*
|
270
270
|
* ```
|
271
271
|
* <script type="module">
|
272
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
272
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
273
273
|
* Monster.DOM.addAttributeToken();
|
274
274
|
* </script>
|
275
275
|
* ```
|
@@ -278,7 +278,7 @@ function toggleAttributeToken(element, key, token) {
|
|
278
278
|
*
|
279
279
|
* ```
|
280
280
|
* <script type="module">
|
281
|
-
* import {addAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
281
|
+
* import {addAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/attributes.js';
|
282
282
|
* addAttributeToken();
|
283
283
|
* </script>
|
284
284
|
* ```
|
@@ -315,7 +315,7 @@ function addAttributeToken(element, key, token) {
|
|
315
315
|
*
|
316
316
|
* ```
|
317
317
|
* <script type="module">
|
318
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
318
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
319
319
|
* Monster.DOM.removeAttributeToken();
|
320
320
|
* </script>
|
321
321
|
* ```
|
@@ -324,7 +324,7 @@ function addAttributeToken(element, key, token) {
|
|
324
324
|
*
|
325
325
|
* ```
|
326
326
|
* <script type="module">
|
327
|
-
* import {removeAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
327
|
+
* import {removeAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/attributes.js';
|
328
328
|
* removeAttributeToken();
|
329
329
|
* </script>
|
330
330
|
* ```
|
@@ -360,7 +360,7 @@ function removeAttributeToken(element, key, token) {
|
|
360
360
|
*
|
361
361
|
* ```
|
362
362
|
* <script type="module">
|
363
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
363
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
364
364
|
* Monster.DOM.containsAttributeToken();
|
365
365
|
* </script>
|
366
366
|
* ```
|
@@ -369,7 +369,7 @@ function removeAttributeToken(element, key, token) {
|
|
369
369
|
*
|
370
370
|
* ```
|
371
371
|
* <script type="module">
|
372
|
-
* import {containsAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
372
|
+
* import {containsAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/attributes.js';
|
373
373
|
* containsAttributeToken();
|
374
374
|
* </script>
|
375
375
|
* ```
|
@@ -402,7 +402,7 @@ function containsAttributeToken(element, key, token) {
|
|
402
402
|
*
|
403
403
|
* ```
|
404
404
|
* <script type="module">
|
405
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
405
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
406
406
|
* Monster.DOM.replaceAttributeToken();
|
407
407
|
* </script>
|
408
408
|
* ```
|
@@ -411,7 +411,7 @@ function containsAttributeToken(element, key, token) {
|
|
411
411
|
*
|
412
412
|
* ```
|
413
413
|
* <script type="module">
|
414
|
-
* import {replaceAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
414
|
+
* import {replaceAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/attributes.js';
|
415
415
|
* replaceAttributeToken();
|
416
416
|
* </script>
|
417
417
|
* ```
|
@@ -447,7 +447,7 @@ function replaceAttributeToken(element, key, from, to) {
|
|
447
447
|
*
|
448
448
|
* ```
|
449
449
|
* <script type="module">
|
450
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
450
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
451
451
|
* Monster.DOM.clearAttributeTokens();
|
452
452
|
* </script>
|
453
453
|
* ```
|
@@ -456,7 +456,7 @@ function replaceAttributeToken(element, key, from, to) {
|
|
456
456
|
*
|
457
457
|
* ```
|
458
458
|
* <script type="module">
|
459
|
-
* import {clearAttributeTokens} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
459
|
+
* import {clearAttributeTokens} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/attributes.js';
|
460
460
|
* clearAttributeTokens();
|
461
461
|
* </script>
|
462
462
|
* ```
|
@@ -486,7 +486,7 @@ function clearAttributeTokens(element, key) {
|
|
486
486
|
*
|
487
487
|
* ```
|
488
488
|
* <script type="module">
|
489
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
489
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
490
490
|
* Monster.DOM.findClosestByAttribute();
|
491
491
|
* </script>
|
492
492
|
* ```
|
@@ -495,7 +495,7 @@ function clearAttributeTokens(element, key) {
|
|
495
495
|
*
|
496
496
|
* ```
|
497
497
|
* <script type="module">
|
498
|
-
* import {findClosestByAttribute} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
498
|
+
* import {findClosestByAttribute} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/attributes.js';
|
499
499
|
* findClosestByAttribute();
|
500
500
|
* </script>
|
501
501
|
* ```
|