@schukai/monster 3.4.2 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. package/example/i18n/providers/embed.mjs +5 -0
  2. package/package.json +1 -1
  3. package/source/constants.mjs +4 -9
  4. package/source/constraints/abstract.mjs +4 -6
  5. package/source/constraints/abstractoperator.mjs +6 -12
  6. package/source/constraints/andoperator.mjs +3 -6
  7. package/source/constraints/invalid.mjs +3 -6
  8. package/source/constraints/isarray.mjs +6 -9
  9. package/source/constraints/isobject.mjs +4 -7
  10. package/source/constraints/namespace.mjs +1 -3
  11. package/source/constraints/oroperator.mjs +26 -25
  12. package/source/constraints/valid.mjs +3 -6
  13. package/source/data/buildmap.mjs +20 -36
  14. package/source/data/buildtree.mjs +29 -29
  15. package/source/data/datasource/namespace.mjs +1 -1
  16. package/source/data/datasource/server/restapi/writeerror.mjs +6 -6
  17. package/source/data/datasource/server/restapi.mjs +51 -65
  18. package/source/data/datasource/server/webconnect.mjs +26 -35
  19. package/source/data/datasource/server.mjs +17 -21
  20. package/source/data/datasource/storage/localstorage.mjs +8 -11
  21. package/source/data/datasource/storage/sessionstorage.mjs +8 -10
  22. package/source/data/datasource/storage.mjs +18 -22
  23. package/source/data/datasource.mjs +27 -43
  24. package/source/data/diff.mjs +20 -32
  25. package/source/data/extend.mjs +20 -14
  26. package/source/data/namespace.mjs +1 -3
  27. package/source/data/pathfinder.mjs +40 -67
  28. package/source/data/pipe.mjs +6 -10
  29. package/source/data/transformer.mjs +141 -157
  30. package/source/dom/assembler.mjs +6 -9
  31. package/source/dom/attributes.mjs +36 -48
  32. package/source/dom/constants.mjs +55 -71
  33. package/source/dom/customcontrol.mjs +16 -21
  34. package/source/dom/customelement.mjs +140 -164
  35. package/source/dom/events.mjs +17 -24
  36. package/source/dom/focusmanager.mjs +30 -48
  37. package/source/dom/locale.mjs +41 -10
  38. package/source/dom/namespace.mjs +1 -1
  39. package/source/dom/ready.mjs +7 -10
  40. package/source/dom/resource/data.mjs +38 -46
  41. package/source/dom/resource/link/namespace.mjs +1 -3
  42. package/source/dom/resource/link/stylesheet.mjs +7 -11
  43. package/source/dom/resource/link.mjs +36 -17
  44. package/source/dom/resource/namespace.mjs +1 -1
  45. package/source/dom/resource/script.mjs +23 -13
  46. package/source/dom/resource.mjs +47 -60
  47. package/source/dom/resourcemanager.mjs +36 -43
  48. package/source/dom/template.mjs +17 -24
  49. package/source/dom/theme.mjs +8 -12
  50. package/source/dom/updater.mjs +150 -196
  51. package/source/dom/util.mjs +11 -12
  52. package/source/dom/worker/factory.mjs +21 -25
  53. package/source/dom/worker/namespace.mjs +1 -1
  54. package/source/i18n/formatter.mjs +20 -24
  55. package/source/i18n/locale.mjs +40 -42
  56. package/source/i18n/namespace.mjs +1 -1
  57. package/source/i18n/provider.mjs +4 -7
  58. package/source/i18n/providers/embed.mjs +115 -0
  59. package/source/i18n/providers/fetch.mjs +33 -38
  60. package/source/i18n/translations.mjs +16 -20
  61. package/source/logging/handler/console.mjs +6 -10
  62. package/source/logging/handler.mjs +15 -18
  63. package/source/logging/logentry.mjs +8 -9
  64. package/source/logging/logger.mjs +73 -55
  65. package/source/logging/namespace.mjs +1 -1
  66. package/source/math/namespace.mjs +1 -1
  67. package/source/math/random.mjs +13 -14
  68. package/source/monster.mjs +132 -100
  69. package/source/net/namespace.mjs +1 -3
  70. package/source/net/webconnect/message.mjs +6 -8
  71. package/source/net/webconnect/namespace.mjs +1 -3
  72. package/source/net/webconnect.mjs +28 -39
  73. package/source/text/formatter.mjs +44 -55
  74. package/source/types/base.mjs +16 -26
  75. package/source/types/basewithoptions.mjs +8 -14
  76. package/source/types/binary.mjs +4 -5
  77. package/source/types/dataurl.mjs +19 -27
  78. package/source/types/global.mjs +14 -26
  79. package/source/types/id.mjs +4 -6
  80. package/source/types/is.mjs +11 -16
  81. package/source/types/mediatype.mjs +29 -44
  82. package/source/types/namespace.mjs +0 -1
  83. package/source/types/node.mjs +16 -22
  84. package/source/types/nodelist.mjs +10 -14
  85. package/source/types/noderecursiveiterator.mjs +11 -14
  86. package/source/types/observablequeue.mjs +13 -16
  87. package/source/types/observer.mjs +16 -23
  88. package/source/types/observerlist.mjs +18 -21
  89. package/source/types/proxyobserver.mjs +24 -37
  90. package/source/types/queue.mjs +8 -13
  91. package/source/types/randomid.mjs +10 -10
  92. package/source/types/regex.mjs +3 -5
  93. package/source/types/stack.mjs +4 -8
  94. package/source/types/tokenlist.mjs +24 -31
  95. package/source/types/typeof.mjs +5 -7
  96. package/source/types/uniquequeue.mjs +8 -13
  97. package/source/types/uuid.mjs +18 -25
  98. package/source/types/validate.mjs +26 -27
  99. package/source/types/version.mjs +17 -25
  100. package/source/util/clone.mjs +23 -32
  101. package/source/util/comparator.mjs +7 -15
  102. package/source/util/deadmansswitch.mjs +16 -23
  103. package/source/util/freeze.mjs +5 -7
  104. package/source/util/namespace.mjs +1 -1
  105. package/source/util/processing.mjs +33 -39
  106. package/source/util/trimspaces.mjs +17 -24
  107. package/test/cases/dom/locale.mjs +15 -0
  108. package/test/cases/i18n/providers/embed.mjs +72 -0
  109. package/test/cases/monster.mjs +1 -1
@@ -5,12 +5,12 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
- import {Base} from '../types/base.mjs';
9
- import {isArray, isInteger, isObject, isPrimitive} from '../types/is.mjs';
10
- import {Stack} from "../types/stack.mjs";
11
- import {validateInteger, validateString} from '../types/validate.mjs';
8
+ import { Base } from "../types/base.mjs";
9
+ import { isArray, isInteger, isObject, isPrimitive } from "../types/is.mjs";
10
+ import { Stack } from "../types/stack.mjs";
11
+ import { validateInteger, validateString } from "../types/validate.mjs";
12
12
 
13
- export {Pathfinder, DELIMITER, WILDCARD}
13
+ export { Pathfinder, DELIMITER, WILDCARD };
14
14
 
15
15
  /**
16
16
  * path separator
@@ -18,13 +18,13 @@ export {Pathfinder, DELIMITER, WILDCARD}
18
18
  * @private
19
19
  * @type {string}
20
20
  */
21
- const DELIMITER = '.';
21
+ const DELIMITER = ".";
22
22
 
23
23
  /**
24
24
  * @private
25
25
  * @type {string}
26
26
  */
27
- const WILDCARD = '*';
27
+ const WILDCARD = "*";
28
28
 
29
29
  /**
30
30
  * Pathfinder is a class to find a path to an object.
@@ -72,7 +72,6 @@ const WILDCARD = '*';
72
72
  * @memberOf Monster.Data
73
73
  */
74
74
  class Pathfinder extends Base {
75
-
76
75
  /**
77
76
  * @param {array|object|Map|Set} value
78
77
  * @since 1.4.0
@@ -82,7 +81,7 @@ class Pathfinder extends Base {
82
81
  super();
83
82
 
84
83
  if (isPrimitive(object)) {
85
- throw new Error('the parameter must not be a simple type');
84
+ throw new Error("the parameter must not be a simple type");
86
85
  }
87
86
 
88
87
  this.object = object;
@@ -165,16 +164,12 @@ class Pathfinder extends Base {
165
164
  try {
166
165
  getValueViaPath.call(this, this.object, path, true);
167
166
  return true;
168
- } catch (e) {
169
-
170
- }
167
+ } catch (e) {}
171
168
 
172
169
  return false;
173
170
  }
174
-
175
171
  }
176
172
 
177
-
178
173
  /**
179
174
  *
180
175
  * @param {*} subject
@@ -187,12 +182,11 @@ class Pathfinder extends Base {
187
182
  * @private
188
183
  */
189
184
  function iterate(subject, path, check) {
190
-
191
- const result = new Map;
185
+ const result = new Map();
192
186
 
193
187
  if (isObject(subject) || isArray(subject)) {
194
188
  for (const [key, value] of Object.entries(subject)) {
195
- result.set(key, getValueViaPath.call(this, value, path, check))
189
+ result.set(key, getValueViaPath.call(this, value, path, check));
196
190
  }
197
191
  } else {
198
192
  let key = path.split(DELIMITER).shift();
@@ -200,15 +194,13 @@ function iterate(subject, path, check) {
200
194
  }
201
195
 
202
196
  return result;
203
-
204
-
205
197
  }
206
198
 
207
199
  /**
208
200
  *
209
201
  * @param {*} subject
210
202
  * @param [string} path
211
- * @param [boolean} check
203
+ * @param [boolean} check
212
204
  * @returns {*}
213
205
  * @throws {TypeError} unsupported type
214
206
  * @throws {Error} the journey is not at its end
@@ -216,12 +208,11 @@ function iterate(subject, path, check) {
216
208
  * @private
217
209
  */
218
210
  function getValueViaPath(subject, path, check) {
219
-
220
211
  if (path === "") {
221
212
  return subject;
222
213
  }
223
214
 
224
- let parts = path.split(DELIMITER)
215
+ let parts = path.split(DELIMITER);
225
216
  let current = parts.shift();
226
217
 
227
218
  if (current === this.wildCard) {
@@ -229,51 +220,43 @@ function getValueViaPath(subject, path, check) {
229
220
  }
230
221
 
231
222
  if (isObject(subject) || isArray(subject)) {
232
-
233
223
  let anchor;
234
224
  if (subject instanceof Map || subject instanceof WeakMap) {
235
225
  anchor = subject.get(current);
236
-
237
226
  } else if (subject instanceof Set || subject instanceof WeakSet) {
238
227
  current = parseInt(current);
239
- validateInteger(current)
228
+ validateInteger(current);
240
229
  anchor = [...subject]?.[current];
241
-
242
- } else if (typeof WeakRef === 'function' && subject instanceof WeakRef) {
243
- throw Error('unsupported action for this data type');
244
-
230
+ } else if (typeof WeakRef === "function" && subject instanceof WeakRef) {
231
+ throw Error("unsupported action for this data type");
245
232
  } else if (isArray(subject)) {
246
233
  current = parseInt(current);
247
- validateInteger(current)
234
+ validateInteger(current);
248
235
  anchor = subject?.[current];
249
236
  } else {
250
237
  anchor = subject?.[current];
251
238
  }
252
239
 
253
240
  if (isObject(anchor) || isArray(anchor)) {
254
- return getValueViaPath.call(this, anchor, parts.join(DELIMITER), check)
241
+ return getValueViaPath.call(this, anchor, parts.join(DELIMITER), check);
255
242
  }
256
243
 
257
244
  if (parts.length > 0) {
258
- throw Error("the journey is not at its end (" + parts.join(DELIMITER) + ")");
245
+ throw Error(`the journey is not at its end (${parts.join(DELIMITER)})`);
259
246
  }
260
247
 
261
-
262
248
  if (check === true) {
263
249
  const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(subject), current);
264
250
 
265
251
  if (!subject.hasOwnProperty(current) && descriptor === undefined) {
266
- throw Error('unknown value');
252
+ throw Error("unknown value");
267
253
  }
268
-
269
254
  }
270
255
 
271
256
  return anchor;
272
-
273
257
  }
274
258
 
275
- throw TypeError("unsupported type " + typeof subject)
276
-
259
+ throw TypeError(`unsupported type ${typeof subject}`);
277
260
  }
278
261
 
279
262
  /**
@@ -289,23 +272,19 @@ function getValueViaPath(subject, path, check) {
289
272
  * @private
290
273
  */
291
274
  function setValueViaPath(object, path, value) {
292
-
293
275
  validateString(path);
294
276
 
295
- let parts = path.split(DELIMITER)
277
+ let parts = path.split(DELIMITER);
296
278
  let last = parts.pop();
297
279
  let subpath = parts.join(DELIMITER);
298
280
 
299
- let stack = new Stack()
281
+ let stack = new Stack();
300
282
  let current = subpath;
301
283
  while (true) {
302
-
303
284
  try {
304
- getValueViaPath.call(this, object, current, true)
285
+ getValueViaPath.call(this, object, current, true);
305
286
  break;
306
- } catch (e) {
307
-
308
- }
287
+ } catch (e) {}
309
288
 
310
289
  stack.push(current);
311
290
  parts.pop();
@@ -323,7 +302,6 @@ function setValueViaPath(object, path, value) {
323
302
  if (isInteger(parseInt(n))) {
324
303
  obj = [];
325
304
  }
326
-
327
305
  }
328
306
 
329
307
  setValueViaPath.call(this, object, current, obj);
@@ -331,27 +309,23 @@ function setValueViaPath(object, path, value) {
331
309
 
332
310
  let anchor = getValueViaPath.call(this, object, subpath);
333
311
 
334
- if (!isObject(object) && !isArray(object)) {
335
- throw TypeError("unsupported type: " + typeof object);
312
+ if (!(isObject(object) || isArray(object))) {
313
+ throw TypeError(`unsupported type: ${typeof object}`);
336
314
  }
337
315
 
338
316
  if (anchor instanceof Map || anchor instanceof WeakMap) {
339
317
  anchor.set(last, value);
340
318
  } else if (anchor instanceof Set || anchor instanceof WeakSet) {
341
- anchor.append(value)
342
-
343
- } else if (typeof WeakRef === 'function' && anchor instanceof WeakRef) {
344
- throw Error('unsupported action for this data type');
345
-
319
+ anchor.append(value);
320
+ } else if (typeof WeakRef === "function" && anchor instanceof WeakRef) {
321
+ throw Error("unsupported action for this data type");
346
322
  } else if (isArray(anchor)) {
347
323
  last = parseInt(last);
348
- validateInteger(last)
324
+ validateInteger(last);
349
325
  assignProperty(anchor, last, value);
350
326
  } else {
351
327
  assignProperty(anchor, last, value);
352
328
  }
353
-
354
-
355
329
  }
356
330
 
357
331
  /**
@@ -361,7 +335,6 @@ function setValueViaPath(object, path, value) {
361
335
  * @param {*} value
362
336
  */
363
337
  function assignProperty(object, key, value) {
364
-
365
338
  if (!object.hasOwnProperty(key)) {
366
339
  object[key] = value;
367
340
  return;
@@ -372,7 +345,6 @@ function assignProperty(object, key, value) {
372
345
  }
373
346
 
374
347
  object[key] = value;
375
-
376
348
  }
377
349
 
378
350
  /**
@@ -389,8 +361,7 @@ function assignProperty(object, key, value) {
389
361
  * @private
390
362
  */
391
363
  function deleteValueViaPath(object, path) {
392
-
393
- const parts = path.split(DELIMITER)
364
+ const parts = path.split(DELIMITER);
394
365
  let last = parts.pop();
395
366
  const subpath = parts.join(DELIMITER);
396
367
 
@@ -398,16 +369,18 @@ function deleteValueViaPath(object, path) {
398
369
 
399
370
  if (anchor instanceof Map) {
400
371
  anchor.delete(last);
401
- } else if (anchor instanceof Set || anchor instanceof WeakMap || anchor instanceof WeakSet || (typeof WeakRef === 'function' && anchor instanceof WeakRef)) {
402
- throw Error('unsupported action for this data type');
403
-
372
+ } else if (
373
+ anchor instanceof Set ||
374
+ anchor instanceof WeakMap ||
375
+ anchor instanceof WeakSet ||
376
+ (typeof WeakRef === "function" && anchor instanceof WeakRef)
377
+ ) {
378
+ throw Error("unsupported action for this data type");
404
379
  } else if (isArray(anchor)) {
405
380
  last = parseInt(last);
406
- validateInteger(last)
381
+ validateInteger(last);
407
382
  delete anchor[last];
408
383
  } else {
409
384
  delete anchor[last];
410
385
  }
411
-
412
-
413
386
  }
@@ -5,17 +5,17 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
- import {Base} from '../types/base.mjs';
9
- import {validateString} from '../types/validate.mjs';
10
- import {Transformer} from './transformer.mjs';
8
+ import { Base } from "../types/base.mjs";
9
+ import { validateString } from "../types/validate.mjs";
10
+ import { Transformer } from "./transformer.mjs";
11
11
 
12
- export {Pipe}
12
+ export { Pipe };
13
13
 
14
14
  /**
15
15
  * @private
16
16
  * @type {string}
17
17
  */
18
- const DELIMITER = '|';
18
+ const DELIMITER = "|";
19
19
 
20
20
  /**
21
21
  * The pipe class makes it possible to combine several processing steps.
@@ -32,7 +32,6 @@ const DELIMITER = '|';
32
32
  * @memberOf Monster.Data
33
33
  */
34
34
  class Pipe extends Base {
35
-
36
35
  /**
37
36
  * @param {string} pipe a pipe consists of commands whose input and output are connected with the pipe symbol `|`.
38
37
  * @throws {TypeError}
@@ -40,12 +39,10 @@ class Pipe extends Base {
40
39
  constructor(pipe) {
41
40
  super();
42
41
  validateString(pipe);
43
-
42
+
44
43
  this.pipe = pipe.split(DELIMITER).map((v) => {
45
44
  return new Transformer(v);
46
45
  });
47
-
48
-
49
46
  }
50
47
 
51
48
  /**
@@ -57,7 +54,6 @@ class Pipe extends Base {
57
54
  * @throws {TypeError} value is not a function
58
55
  */
59
56
  setCallback(name, callback, context) {
60
-
61
57
  for (const [, t] of Object.entries(this.pipe)) {
62
58
  t.setCallback(name, callback, context);
63
59
  }