@schukai/monster 1.23.0 → 1.26.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. package/CHANGELOG +53 -0
  2. package/README.md +4 -4
  3. package/dist/modules/constants.js +2 -2
  4. package/dist/modules/constraints/abstract.js +1 -1
  5. package/dist/modules/constraints/abstractoperator.js +1 -1
  6. package/dist/modules/constraints/andoperator.js +1 -1
  7. package/dist/modules/constraints/invalid.js +1 -1
  8. package/dist/modules/constraints/isarray.js +1 -1
  9. package/dist/modules/constraints/isobject.js +1 -1
  10. package/dist/modules/constraints/namespace.js +1 -1
  11. package/dist/modules/constraints/oroperator.js +1 -1
  12. package/dist/modules/constraints/valid.js +1 -1
  13. package/dist/modules/data/buildmap.js +2 -2
  14. package/dist/modules/data/buildtree.js +2 -0
  15. package/dist/modules/data/datasource/namespace.js +1 -1
  16. package/dist/modules/data/datasource/restapi/writeerror.js +2 -0
  17. package/dist/modules/data/datasource/restapi.js +2 -2
  18. package/dist/modules/data/datasource/storage/localstorage.js +2 -2
  19. package/dist/modules/data/datasource/storage/namespace.js +1 -1
  20. package/dist/modules/data/datasource/storage/sessionstorage.js +2 -2
  21. package/dist/modules/data/datasource/storage.js +2 -2
  22. package/dist/modules/data/datasource.js +2 -2
  23. package/dist/modules/data/diff.js +2 -2
  24. package/dist/modules/data/extend.js +1 -1
  25. package/dist/modules/data/namespace.js +1 -1
  26. package/dist/modules/data/pathfinder.js +2 -2
  27. package/dist/modules/data/pipe.js +1 -1
  28. package/dist/modules/data/transformer.js +2 -2
  29. package/dist/modules/dom/assembler.js +1 -1
  30. package/dist/modules/dom/attributes.js +1 -1
  31. package/dist/modules/dom/constants.js +2 -2
  32. package/dist/modules/dom/customcontrol.js +2 -2
  33. package/dist/modules/dom/customelement.js +2 -2
  34. package/dist/modules/dom/events.js +1 -1
  35. package/dist/modules/dom/focusmanager.js +2 -0
  36. package/dist/modules/dom/locale.js +1 -1
  37. package/dist/modules/dom/namespace.js +1 -1
  38. package/dist/modules/dom/resource/data.js +2 -0
  39. package/dist/modules/dom/resource/link/stylesheet.js +2 -0
  40. package/dist/modules/dom/resource/link.js +2 -0
  41. package/dist/modules/dom/resource/script.js +2 -0
  42. package/dist/modules/dom/resource.js +2 -0
  43. package/dist/modules/dom/resourcemanager.js +2 -0
  44. package/dist/modules/dom/template.js +2 -2
  45. package/dist/modules/dom/theme.js +1 -1
  46. package/dist/modules/dom/updater.js +2 -2
  47. package/dist/modules/dom/util.js +1 -1
  48. package/dist/modules/dom/worker/factory.js +2 -0
  49. package/dist/modules/i18n/formatter.js +2 -0
  50. package/dist/modules/i18n/locale.js +1 -1
  51. package/dist/modules/i18n/namespace.js +1 -1
  52. package/dist/modules/i18n/provider.js +1 -1
  53. package/dist/modules/i18n/providers/fetch.js +2 -2
  54. package/dist/modules/i18n/providers/namespace.js +1 -1
  55. package/dist/modules/i18n/translations.js +1 -1
  56. package/dist/modules/logging/handler/console.js +1 -1
  57. package/dist/modules/logging/handler/namespace.js +1 -1
  58. package/dist/modules/logging/handler.js +1 -1
  59. package/dist/modules/logging/logentry.js +1 -1
  60. package/dist/modules/logging/logger.js +1 -1
  61. package/dist/modules/logging/namespace.js +1 -1
  62. package/dist/modules/math/namespace.js +1 -1
  63. package/dist/modules/math/random.js +2 -2
  64. package/dist/modules/monster.js +1 -1
  65. package/dist/modules/namespace.js +1 -1
  66. package/dist/modules/text/formatter.js +2 -2
  67. package/dist/modules/text/namespace.js +1 -1
  68. package/dist/modules/types/base.js +1 -1
  69. package/dist/modules/types/basewithoptions.js +2 -2
  70. package/dist/modules/types/binary.js +1 -1
  71. package/dist/modules/types/dataurl.js +1 -1
  72. package/dist/modules/types/global.js +1 -1
  73. package/dist/modules/types/id.js +1 -1
  74. package/dist/modules/types/is.js +2 -2
  75. package/dist/modules/types/mediatype.js +1 -1
  76. package/dist/modules/types/namespace.js +1 -1
  77. package/dist/modules/types/node.js +2 -0
  78. package/dist/modules/types/nodelist.js +2 -0
  79. package/dist/modules/types/noderecursiveiterator.js +2 -0
  80. package/dist/modules/types/observer.js +1 -1
  81. package/dist/modules/types/observerlist.js +2 -2
  82. package/dist/modules/types/proxyobserver.js +2 -2
  83. package/dist/modules/types/queue.js +1 -1
  84. package/dist/modules/types/randomid.js +1 -1
  85. package/dist/modules/types/regex.js +2 -0
  86. package/dist/modules/types/stack.js +1 -1
  87. package/dist/modules/types/tokenlist.js +2 -2
  88. package/dist/modules/types/typeof.js +1 -1
  89. package/dist/modules/types/uniquequeue.js +1 -1
  90. package/dist/modules/types/uuid.js +2 -0
  91. package/dist/modules/types/validate.js +1 -1
  92. package/dist/modules/types/version.js +2 -2
  93. package/dist/modules/util/clone.js +1 -1
  94. package/dist/modules/util/comparator.js +2 -2
  95. package/dist/modules/util/freeze.js +1 -1
  96. package/dist/modules/util/namespace.js +1 -1
  97. package/dist/modules/util/processing.js +2 -2
  98. package/dist/modules/util/trimspaces.js +2 -0
  99. package/dist/monster.dev.js +1684 -696
  100. package/dist/monster.dev.js.map +1 -1
  101. package/dist/monster.js +2 -2
  102. package/package.json +13 -2
  103. package/source/constants.js +16 -7
  104. package/source/constraints/abstract.js +5 -0
  105. package/source/constraints/abstractoperator.js +5 -0
  106. package/source/constraints/andoperator.js +10 -5
  107. package/source/constraints/invalid.js +8 -3
  108. package/source/constraints/isarray.js +9 -4
  109. package/source/constraints/isobject.js +8 -3
  110. package/source/constraints/oroperator.js +10 -5
  111. package/source/constraints/valid.js +8 -3
  112. package/source/data/buildmap.js +27 -11
  113. package/source/data/buildtree.js +95 -0
  114. package/source/data/datasource/restapi/writeerror.js +49 -0
  115. package/source/data/datasource/restapi.js +87 -20
  116. package/source/data/datasource/storage/localstorage.js +4 -10
  117. package/source/data/datasource/storage/sessionstorage.js +4 -12
  118. package/source/data/datasource/storage.js +7 -14
  119. package/source/data/datasource.js +55 -17
  120. package/source/data/diff.js +8 -8
  121. package/source/data/extend.js +5 -5
  122. package/source/data/pathfinder.js +12 -6
  123. package/source/data/pipe.js +6 -5
  124. package/source/data/transformer.js +131 -24
  125. package/source/dom/assembler.js +2 -2
  126. package/source/dom/attributes.js +24 -24
  127. package/source/dom/constants.js +305 -12
  128. package/source/dom/customcontrol.js +40 -19
  129. package/source/dom/customelement.js +121 -92
  130. package/source/dom/events.js +6 -6
  131. package/source/dom/focusmanager.js +250 -0
  132. package/source/dom/locale.js +10 -5
  133. package/source/dom/resource/data.js +170 -0
  134. package/source/dom/resource/link/stylesheet.js +54 -0
  135. package/source/dom/resource/link.js +125 -0
  136. package/source/dom/resource/script.js +112 -0
  137. package/source/dom/resource.js +268 -0
  138. package/source/dom/resourcemanager.js +214 -0
  139. package/source/dom/template.js +52 -12
  140. package/source/dom/theme.js +3 -3
  141. package/source/dom/updater.js +47 -33
  142. package/source/dom/util.js +6 -6
  143. package/source/dom/worker/factory.js +134 -0
  144. package/source/i18n/formatter.js +140 -0
  145. package/source/i18n/locale.js +10 -8
  146. package/source/i18n/provider.js +4 -4
  147. package/source/i18n/providers/fetch.js +24 -14
  148. package/source/i18n/translations.js +20 -10
  149. package/source/logging/handler/console.js +2 -2
  150. package/source/logging/handler.js +2 -2
  151. package/source/logging/logentry.js +2 -2
  152. package/source/logging/logger.js +4 -4
  153. package/source/math/random.js +11 -5
  154. package/source/namespace.js +1 -1
  155. package/source/text/formatter.js +244 -27
  156. package/source/types/base.js +4 -4
  157. package/source/types/basewithoptions.js +10 -15
  158. package/source/types/binary.js +4 -4
  159. package/source/types/dataurl.js +6 -6
  160. package/source/types/global.js +9 -7
  161. package/source/types/id.js +6 -3
  162. package/source/types/is.js +103 -85
  163. package/source/types/mediatype.js +4 -4
  164. package/source/types/node.js +179 -0
  165. package/source/types/nodelist.js +125 -0
  166. package/source/types/noderecursiveiterator.js +126 -0
  167. package/source/types/observer.js +3 -3
  168. package/source/types/observerlist.js +3 -3
  169. package/source/types/proxyobserver.js +24 -7
  170. package/source/types/queue.js +6 -6
  171. package/source/types/randomid.js +2 -2
  172. package/source/types/regex.js +49 -0
  173. package/source/types/stack.js +2 -2
  174. package/source/types/tokenlist.js +8 -9
  175. package/source/types/typeof.js +3 -3
  176. package/source/types/uniquequeue.js +4 -4
  177. package/source/types/uuid.js +102 -0
  178. package/source/types/validate.js +20 -20
  179. package/source/types/version.js +6 -6
  180. package/source/util/clone.js +4 -5
  181. package/source/util/comparator.js +5 -5
  182. package/source/util/freeze.js +5 -5
  183. package/source/util/processing.js +33 -36
  184. package/source/util/trimspaces.js +85 -0
  185. package/test/cases/data/buildtree.js +149 -0
  186. package/test/cases/data/datasource/restapi.js +1 -1
  187. package/test/cases/data/datasource.js +4 -4
  188. package/test/cases/data/diff.js +4 -4
  189. package/test/cases/data/pathfinder.js +18 -9
  190. package/test/cases/data/pipe.js +26 -2
  191. package/test/cases/data/transformer.js +41 -10
  192. package/test/cases/dom/attributes.js +18 -14
  193. package/test/cases/dom/customcontrol.js +6 -5
  194. package/test/cases/dom/customelement.js +14 -16
  195. package/test/cases/dom/focusmanager.js +111 -0
  196. package/test/cases/dom/locale.js +1 -4
  197. package/test/cases/dom/resource/data.js +129 -0
  198. package/test/cases/dom/resource/link/stylesheet.js +101 -0
  199. package/test/cases/dom/resource/link.js +101 -0
  200. package/test/cases/dom/resource/script.js +115 -0
  201. package/test/cases/dom/resourcemanager.js +118 -0
  202. package/test/cases/dom/updater.js +28 -4
  203. package/test/cases/dom/worker/factory.js +63 -0
  204. package/test/cases/i18n/formatter.js +66 -0
  205. package/test/cases/monster.js +1 -1
  206. package/test/cases/text/formatter.js +71 -8
  207. package/test/cases/types/node.js +196 -0
  208. package/test/cases/types/nodelist.js +64 -0
  209. package/test/cases/types/noderecursiveiterator.js +54 -0
  210. package/test/cases/types/proxyobserver.js +55 -11
  211. package/test/cases/types/regex.js +32 -0
  212. package/test/cases/types/uuid.js +42 -0
  213. package/test/cases/util/freeze.js +30 -4
  214. package/test/cases/util/trimspaces.js +24 -0
  215. package/test/util/cleanupdom.js +48 -0
  216. package/test/util/jsdom.js +22 -9
  217. package/test/web/import.js +15 -0
  218. package/test/web/monster-dev.html +3 -3
  219. package/test/web/monster.html +2 -2
  220. package/test/web/test.html +3 -3
  221. package/test/web/tests.js +7 -7
@@ -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.0/dist/modules/data/pipe.js';
23
- * console.log(new Monster.Data.Pipe())
22
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/data/pipe.js';
32
- * console.log(new Pipe())
31
+ * import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/data/pipe.js';
42
+ * import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/data/transformer.js';
29
- * console.log(new Monster.Data.Transformer())
28
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/data/transformer.js';
38
- * console.log(new Transformer())
37
+ * import {Transformer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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 | | | Converts the value to 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 | | | If the value is undefined the first argument is returned, otherwise the value. (since 1.12.0) |
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.23.0/dist/modules/data/transformer.js';
123
+ * import {Transformer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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 quotable
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
- return btoa(value);
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 = (args.shift() || 'undefined');
417
- let defaultValue = (args.shift() || '');
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 = (args.shift() || 'undefined');
440
- return new Pathfinder(value).getVia(key);
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
- return args[0];
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)
@@ -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.23.0/dist/modules/dom/assembler.js';
26
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/assembler.js';
35
+ * import {Assembler} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/dom/assembler.js';
36
36
  * console.log(new Assembler())
37
37
  * </script>
38
38
  * ```
@@ -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.0/dist/modules/dom/updater.js';
23
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/updater.js';
32
+ * import {getUpdaterFromNode} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
53
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
62
+ * import {addToObjectLink} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
95
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
104
+ * import {removeObjectLink} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
137
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
146
+ * import {hasObjectLink} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
183
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
192
+ * import {getLinkedObjects} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
228
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
237
+ * import {toggleAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
272
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
281
+ * import {addAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
318
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
327
+ * import {removeAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
363
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
372
+ * import {containsAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
405
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
414
+ * import {replaceAttributeToken} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
450
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
459
+ * import {clearAttributeTokens} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
489
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/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.23.0/dist/modules/dom/attributes.js';
498
+ * import {findClosestByAttribute} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/dom/attributes.js';
499
499
  * findClosestByAttribute();
500
500
  * </script>
501
501
  * ```