@schukai/monster 3.5.0 → 3.7.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/source/constants.mjs +4 -9
- package/source/constraints/abstract.mjs +4 -6
- package/source/constraints/abstractoperator.mjs +6 -12
- package/source/constraints/andoperator.mjs +3 -6
- package/source/constraints/invalid.mjs +3 -6
- package/source/constraints/isarray.mjs +6 -9
- package/source/constraints/isobject.mjs +4 -7
- package/source/constraints/namespace.mjs +1 -3
- package/source/constraints/oroperator.mjs +26 -25
- package/source/constraints/valid.mjs +3 -6
- package/source/data/buildmap.mjs +20 -36
- package/source/data/buildtree.mjs +29 -29
- package/source/data/datasource/namespace.mjs +1 -1
- package/source/data/datasource/server/restapi/writeerror.mjs +6 -6
- package/source/data/datasource/server/restapi.mjs +51 -65
- package/source/data/datasource/server/webconnect.mjs +26 -35
- package/source/data/datasource/server.mjs +16 -20
- package/source/data/datasource/storage/localstorage.mjs +8 -11
- package/source/data/datasource/storage/sessionstorage.mjs +8 -10
- package/source/data/datasource/storage.mjs +18 -22
- package/source/data/datasource.mjs +27 -43
- package/source/data/diff.mjs +20 -32
- package/source/data/extend.mjs +20 -14
- package/source/data/namespace.mjs +1 -3
- package/source/data/pathfinder.mjs +40 -67
- package/source/data/pipe.mjs +6 -10
- package/source/data/transformer.mjs +141 -157
- package/source/dom/assembler.mjs +6 -9
- package/source/dom/attributes.mjs +36 -48
- package/source/dom/constants.mjs +55 -71
- package/source/dom/customcontrol.mjs +16 -21
- package/source/dom/customelement.mjs +140 -164
- package/source/dom/events.mjs +17 -24
- package/source/dom/focusmanager.mjs +30 -48
- package/source/dom/locale.mjs +16 -19
- package/source/dom/namespace.mjs +1 -1
- package/source/dom/ready.mjs +7 -10
- package/source/dom/resource/data.mjs +38 -46
- package/source/dom/resource/link/namespace.mjs +1 -3
- package/source/dom/resource/link/stylesheet.mjs +7 -11
- package/source/dom/resource/link.mjs +36 -17
- package/source/dom/resource/namespace.mjs +1 -1
- package/source/dom/resource/script.mjs +23 -13
- package/source/dom/resource.mjs +47 -60
- package/source/dom/resourcemanager.mjs +36 -43
- package/source/dom/template.mjs +17 -24
- package/source/dom/theme.mjs +8 -12
- package/source/dom/updater.mjs +150 -196
- package/source/dom/util.mjs +11 -12
- package/source/dom/worker/factory.mjs +21 -25
- package/source/dom/worker/namespace.mjs +1 -1
- package/source/i18n/formatter.mjs +20 -24
- package/source/i18n/locale.mjs +40 -42
- package/source/i18n/namespace.mjs +1 -1
- package/source/i18n/provider.mjs +4 -7
- package/source/i18n/providers/embed.mjs +16 -26
- package/source/i18n/providers/fetch.mjs +30 -36
- package/source/i18n/translations.mjs +15 -22
- package/source/logging/handler/console.mjs +6 -10
- package/source/logging/handler.mjs +15 -18
- package/source/logging/logentry.mjs +8 -9
- package/source/logging/logger.mjs +73 -55
- package/source/logging/namespace.mjs +1 -1
- package/source/math/namespace.mjs +1 -1
- package/source/math/random.mjs +13 -14
- package/source/monster.mjs +132 -100
- package/source/net/namespace.mjs +1 -3
- package/source/net/webconnect/message.mjs +6 -8
- package/source/net/webconnect/namespace.mjs +1 -3
- package/source/net/webconnect.mjs +28 -39
- package/source/text/formatter.mjs +44 -55
- package/source/types/base.mjs +16 -26
- package/source/types/basewithoptions.mjs +8 -14
- package/source/types/binary.mjs +4 -5
- package/source/types/dataurl.mjs +19 -27
- package/source/types/global.mjs +14 -26
- package/source/types/id.mjs +4 -6
- package/source/types/is.mjs +11 -16
- package/source/types/mediatype.mjs +29 -44
- package/source/types/namespace.mjs +0 -1
- package/source/types/node.mjs +16 -22
- package/source/types/nodelist.mjs +10 -14
- package/source/types/noderecursiveiterator.mjs +11 -14
- package/source/types/observablequeue.mjs +13 -16
- package/source/types/observer.mjs +16 -23
- package/source/types/observerlist.mjs +18 -21
- package/source/types/proxyobserver.mjs +24 -37
- package/source/types/queue.mjs +8 -13
- package/source/types/randomid.mjs +10 -10
- package/source/types/regex.mjs +3 -5
- package/source/types/stack.mjs +4 -8
- package/source/types/tokenlist.mjs +24 -31
- package/source/types/typeof.mjs +5 -7
- package/source/types/uniquequeue.mjs +8 -13
- package/source/types/uuid.mjs +18 -25
- package/source/types/validate.mjs +26 -27
- package/source/types/version.mjs +17 -25
- package/source/util/clone.mjs +23 -32
- package/source/util/comparator.mjs +7 -15
- package/source/util/deadmansswitch.mjs +16 -23
- package/source/util/freeze.mjs +5 -7
- package/source/util/namespace.mjs +1 -1
- package/source/util/processing.mjs +33 -39
- package/source/util/trimspaces.mjs +17 -24
- 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
|
9
|
-
import {isArray, isInteger, isObject, isPrimitive} from
|
10
|
-
import {Stack} from "../types/stack.mjs";
|
11
|
-
import {validateInteger, validateString} from
|
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(
|
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
|
-
|
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(
|
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(
|
252
|
+
throw Error("unknown value");
|
267
253
|
}
|
268
|
-
|
269
254
|
}
|
270
255
|
|
271
256
|
return anchor;
|
272
|
-
|
273
257
|
}
|
274
258
|
|
275
|
-
throw TypeError(
|
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)
|
335
|
-
throw TypeError(
|
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
|
-
|
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 (
|
402
|
-
|
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
|
}
|
package/source/data/pipe.mjs
CHANGED
@@ -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
|
9
|
-
import {validateString} from
|
10
|
-
import {Transformer} from
|
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
|
}
|