@schukai/monster 3.5.0 → 3.8.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 +105 -87
- 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 +31 -49
- package/source/dom/locale.mjs +18 -20
- 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 +42 -55
- 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 +17 -24
- 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
@@ -1,5 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
/**
|
4
2
|
* Copyright schukai GmbH and contributors 2022. All Rights Reserved.
|
5
3
|
* Node module: @schukai/monster
|
@@ -7,22 +5,21 @@
|
|
7
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
8
6
|
*/
|
9
7
|
|
10
|
-
|
11
|
-
import {
|
12
|
-
import {
|
13
|
-
import {
|
14
|
-
import {isArray, isObject, isString} from '../types/is.mjs';
|
8
|
+
import { Base } from "../types/base.mjs";
|
9
|
+
import { getGlobal, getGlobalObject } from "../types/global.mjs";
|
10
|
+
import { ID } from "../types/id.mjs";
|
11
|
+
import { isArray, isObject, isString } from "../types/is.mjs";
|
15
12
|
import {
|
16
13
|
validateFunction,
|
17
14
|
validateInteger,
|
18
15
|
validateObject,
|
19
16
|
validatePrimitive,
|
20
|
-
validateString
|
21
|
-
} from
|
22
|
-
import {clone} from "../util/clone.mjs";
|
23
|
-
import {Pathfinder} from "./pathfinder.mjs";
|
17
|
+
validateString,
|
18
|
+
} from "../types/validate.mjs";
|
19
|
+
import { clone } from "../util/clone.mjs";
|
20
|
+
import { Pathfinder } from "./pathfinder.mjs";
|
24
21
|
|
25
|
-
export {Transformer}
|
22
|
+
export { Transformer };
|
26
23
|
|
27
24
|
/**
|
28
25
|
* The transformer class is a swiss army knife for manipulating values. especially in combination with the pipe, processing chains can be built up.
|
@@ -82,7 +79,7 @@ export {Transformer}
|
|
82
79
|
* url: 'http://example.com/',
|
83
80
|
* pretendToBeVisual: true
|
84
81
|
* });
|
85
|
-
*
|
82
|
+
*
|
86
83
|
* [
|
87
84
|
* 'self',
|
88
85
|
* 'document',
|
@@ -120,9 +117,8 @@ class Transformer extends Base {
|
|
120
117
|
constructor(definition) {
|
121
118
|
super();
|
122
119
|
this.args = disassemble(definition);
|
123
|
-
this.command = this.args.shift()
|
120
|
+
this.command = this.args.shift();
|
124
121
|
this.callbacks = new Map();
|
125
|
-
|
126
122
|
}
|
127
123
|
|
128
124
|
/**
|
@@ -135,8 +131,8 @@ class Transformer extends Base {
|
|
135
131
|
* @throws {TypeError} value is not a function
|
136
132
|
*/
|
137
133
|
setCallback(name, callback, context) {
|
138
|
-
validateString(name)
|
139
|
-
validateFunction(callback)
|
134
|
+
validateString(name);
|
135
|
+
validateFunction(callback);
|
140
136
|
|
141
137
|
if (context !== undefined) {
|
142
138
|
validateObject(context);
|
@@ -159,7 +155,7 @@ class Transformer extends Base {
|
|
159
155
|
* @throws {Error} type not supported
|
160
156
|
*/
|
161
157
|
run(value) {
|
162
|
-
return transform.apply(this, [value])
|
158
|
+
return transform.apply(this, [value]);
|
163
159
|
}
|
164
160
|
}
|
165
161
|
|
@@ -170,33 +166,31 @@ class Transformer extends Base {
|
|
170
166
|
* @private
|
171
167
|
*/
|
172
168
|
function disassemble(command) {
|
173
|
-
|
174
169
|
validateString(command);
|
175
170
|
|
176
|
-
let placeholder = new Map;
|
177
|
-
const regex = /((?<pattern>\\(?<char>.)){1})/
|
171
|
+
let placeholder = new Map();
|
172
|
+
const regex = /((?<pattern>\\(?<char>.)){1})/gim;
|
178
173
|
|
179
174
|
// The separator for args must be escaped
|
180
175
|
// undefined string which should not occur normally and is also not a regex
|
181
|
-
let result = command.matchAll(regex)
|
176
|
+
let result = command.matchAll(regex);
|
182
177
|
|
183
178
|
for (let m of result) {
|
184
|
-
let g = m?.[
|
179
|
+
let g = m?.["groups"];
|
185
180
|
if (!isObject(g)) {
|
186
181
|
continue;
|
187
182
|
}
|
188
183
|
|
189
|
-
let p = g?.[
|
190
|
-
let c = g?.[
|
184
|
+
let p = g?.["pattern"];
|
185
|
+
let c = g?.["char"];
|
191
186
|
|
192
187
|
if (p && c) {
|
193
|
-
let r =
|
188
|
+
let r = `__${new ID().toString()}__`;
|
194
189
|
placeholder.set(r, c);
|
195
190
|
command = command.replace(p, r);
|
196
191
|
}
|
197
|
-
|
198
192
|
}
|
199
|
-
let parts = command.split(
|
193
|
+
let parts = command.split(":");
|
200
194
|
|
201
195
|
parts = parts.map(function (value) {
|
202
196
|
let v = value.trim();
|
@@ -204,11 +198,9 @@ function disassemble(command) {
|
|
204
198
|
v = v.replace(k[0], k[1]);
|
205
199
|
}
|
206
200
|
return v;
|
207
|
-
|
208
|
-
|
209
201
|
});
|
210
202
|
|
211
|
-
return parts
|
203
|
+
return parts;
|
212
204
|
}
|
213
205
|
|
214
206
|
/**
|
@@ -219,12 +211,11 @@ function disassemble(command) {
|
|
219
211
|
* @private
|
220
212
|
*/
|
221
213
|
function convertToString(value) {
|
222
|
-
|
223
|
-
if (isObject(value) && value.hasOwnProperty('toString')) {
|
214
|
+
if (isObject(value) && value.hasOwnProperty("toString")) {
|
224
215
|
value = value.toString();
|
225
216
|
}
|
226
217
|
|
227
|
-
validateString(value)
|
218
|
+
validateString(value);
|
228
219
|
return value;
|
229
220
|
}
|
230
221
|
|
@@ -239,59 +230,56 @@ function convertToString(value) {
|
|
239
230
|
* @throws {Error} missing key parameter
|
240
231
|
*/
|
241
232
|
function transform(value) {
|
242
|
-
|
243
|
-
const console = getGlobalObject('console');
|
233
|
+
const console = getGlobalObject("console");
|
244
234
|
|
245
235
|
let args = clone(this.args);
|
246
|
-
let key
|
236
|
+
let key;
|
237
|
+
let defaultValue;
|
247
238
|
|
248
239
|
switch (this.command) {
|
240
|
+
case "static":
|
241
|
+
return this.args.join(":");
|
249
242
|
|
250
|
-
case
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
case 'strtolower':
|
255
|
-
case 'tolowercase':
|
256
|
-
validateString(value)
|
243
|
+
case "tolower":
|
244
|
+
case "strtolower":
|
245
|
+
case "tolowercase":
|
246
|
+
validateString(value);
|
257
247
|
return value.toLowerCase();
|
258
248
|
|
259
|
-
case
|
260
|
-
case
|
261
|
-
case
|
262
|
-
validateString(value)
|
249
|
+
case "toupper":
|
250
|
+
case "strtoupper":
|
251
|
+
case "touppercase":
|
252
|
+
validateString(value);
|
263
253
|
return value.toUpperCase();
|
264
254
|
|
265
|
-
case
|
266
|
-
return
|
255
|
+
case "tostring":
|
256
|
+
return `${value}`;
|
267
257
|
|
268
|
-
case
|
258
|
+
case "tointeger":
|
269
259
|
let n = parseInt(value);
|
270
260
|
validateInteger(n);
|
271
|
-
return n
|
261
|
+
return n;
|
272
262
|
|
273
|
-
case
|
263
|
+
case "tojson":
|
274
264
|
return JSON.stringify(value);
|
275
265
|
|
276
|
-
case
|
266
|
+
case "fromjson":
|
277
267
|
return JSON.parse(value);
|
278
268
|
|
279
|
-
case
|
280
|
-
validateString(value)
|
269
|
+
case "trim":
|
270
|
+
validateString(value);
|
281
271
|
return value.trim();
|
282
272
|
|
283
|
-
case
|
284
|
-
validateString(value)
|
273
|
+
case "rawurlencode":
|
274
|
+
validateString(value);
|
285
275
|
return encodeURIComponent(value)
|
286
|
-
.replace(/!/g,
|
287
|
-
.replace(/'/g,
|
288
|
-
.replace(/\(/g,
|
289
|
-
.replace(/\)/g,
|
290
|
-
.replace(/\*/g,
|
291
|
-
|
292
|
-
|
293
|
-
case 'call':
|
276
|
+
.replace(/!/g, "%21")
|
277
|
+
.replace(/'/g, "%27")
|
278
|
+
.replace(/\(/g, "%28")
|
279
|
+
.replace(/\)/g, "%29")
|
280
|
+
.replace(/\*/g, "%2A");
|
294
281
|
|
282
|
+
case "call":
|
295
283
|
/**
|
296
284
|
* callback-definition
|
297
285
|
* function callback(value, ...args) {
|
@@ -307,9 +295,9 @@ function transform(value) {
|
|
307
295
|
callback = value[callbackName];
|
308
296
|
} else if (this.callbacks.has(callbackName)) {
|
309
297
|
let s = this.callbacks.get(callbackName);
|
310
|
-
callback = s?.[
|
311
|
-
context = s?.[
|
312
|
-
} else if (typeof window ===
|
298
|
+
callback = s?.["callback"];
|
299
|
+
context = s?.["context"];
|
300
|
+
} else if (typeof window === "object" && window.hasOwnProperty(callbackName)) {
|
313
301
|
callback = window[callbackName];
|
314
302
|
}
|
315
303
|
validateFunction(callback);
|
@@ -317,119 +305,117 @@ function transform(value) {
|
|
317
305
|
args.unshift(value);
|
318
306
|
return callback.call(context, ...args);
|
319
307
|
|
320
|
-
case
|
321
|
-
case
|
308
|
+
case "plain":
|
309
|
+
case "plaintext":
|
322
310
|
validateString(value);
|
323
|
-
let doc = new DOMParser().parseFromString(value,
|
311
|
+
let doc = new DOMParser().parseFromString(value, "text/html");
|
324
312
|
return doc.body.textContent || "";
|
325
313
|
|
326
|
-
case
|
327
|
-
case
|
328
|
-
|
314
|
+
case "if":
|
315
|
+
case "?":
|
329
316
|
validatePrimitive(value);
|
330
317
|
|
331
|
-
let trueStatement =
|
332
|
-
let falseStatement =
|
318
|
+
let trueStatement = args.shift() || undefined;
|
319
|
+
let falseStatement = args.shift() || undefined;
|
333
320
|
|
334
|
-
if (trueStatement ===
|
321
|
+
if (trueStatement === "value") {
|
335
322
|
trueStatement = value;
|
336
323
|
}
|
337
|
-
if (trueStatement ===
|
338
|
-
trueStatement =
|
324
|
+
if (trueStatement === "\\value") {
|
325
|
+
trueStatement = "value";
|
339
326
|
}
|
340
|
-
if (falseStatement ===
|
327
|
+
if (falseStatement === "value") {
|
341
328
|
falseStatement = value;
|
342
329
|
}
|
343
|
-
if (falseStatement ===
|
344
|
-
falseStatement =
|
330
|
+
if (falseStatement === "\\value") {
|
331
|
+
falseStatement = "value";
|
345
332
|
}
|
346
333
|
|
347
|
-
let condition =
|
334
|
+
let condition =
|
335
|
+
(value !== undefined && value !== "" && value !== "off" && value !== "false" && value !== false) ||
|
336
|
+
value === "on" ||
|
337
|
+
value === "true" ||
|
338
|
+
value === true;
|
348
339
|
return condition ? trueStatement : falseStatement;
|
349
340
|
|
350
|
-
|
351
|
-
case 'ucfirst':
|
341
|
+
case "ucfirst":
|
352
342
|
validateString(value);
|
353
343
|
|
354
344
|
let firstchar = value.charAt(0).toUpperCase();
|
355
345
|
return firstchar + value.substr(1);
|
356
|
-
case
|
346
|
+
case "ucwords":
|
357
347
|
validateString(value);
|
358
348
|
|
359
349
|
return value.replace(/^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g, function (v) {
|
360
350
|
return v.toUpperCase();
|
361
351
|
});
|
362
352
|
|
363
|
-
case
|
364
|
-
case
|
365
|
-
|
366
|
-
if ((isString(value) || isObject(value) || isArray(value)) && value.hasOwnProperty('length')) {
|
353
|
+
case "count":
|
354
|
+
case "length":
|
355
|
+
if ((isString(value) || isObject(value) || isArray(value)) && value.hasOwnProperty("length")) {
|
367
356
|
return value.length;
|
368
357
|
}
|
369
358
|
|
370
|
-
throw new TypeError(
|
359
|
+
throw new TypeError(`unsupported type ${typeof value}`);
|
371
360
|
|
372
|
-
case
|
373
|
-
case
|
374
|
-
case
|
361
|
+
case "to-base64":
|
362
|
+
case "btoa":
|
363
|
+
case "base64":
|
375
364
|
return btoa(convertToString(value));
|
376
365
|
|
377
|
-
case
|
378
|
-
case
|
366
|
+
case "atob":
|
367
|
+
case "from-base64":
|
379
368
|
return atob(convertToString(value));
|
380
369
|
|
381
|
-
case
|
382
|
-
return
|
370
|
+
case "empty":
|
371
|
+
return "";
|
383
372
|
|
384
|
-
case
|
373
|
+
case "undefined":
|
385
374
|
return undefined;
|
386
375
|
|
387
|
-
case
|
388
|
-
|
376
|
+
case "debug":
|
389
377
|
if (isObject(console)) {
|
390
378
|
console.log(value);
|
391
379
|
}
|
392
380
|
|
393
381
|
return value;
|
394
382
|
|
395
|
-
case
|
383
|
+
case "prefix":
|
396
384
|
validateString(value);
|
397
385
|
let prefix = args?.[0];
|
398
386
|
return prefix + value;
|
399
387
|
|
400
|
-
case
|
388
|
+
case "suffix":
|
401
389
|
validateString(value);
|
402
390
|
let suffix = args?.[0];
|
403
391
|
return value + suffix;
|
404
392
|
|
405
|
-
case
|
406
|
-
return
|
407
|
-
|
408
|
-
case 'first-key':
|
409
|
-
case 'last-key':
|
410
|
-
case 'nth-last-key':
|
411
|
-
case 'nth-key':
|
393
|
+
case "uniqid":
|
394
|
+
return new ID().toString();
|
412
395
|
|
396
|
+
case "first-key":
|
397
|
+
case "last-key":
|
398
|
+
case "nth-last-key":
|
399
|
+
case "nth-key":
|
413
400
|
if (!isObject(value)) {
|
414
|
-
throw new Error("type not supported")
|
401
|
+
throw new Error("type not supported");
|
415
402
|
}
|
416
403
|
|
417
|
-
const keys = Object.keys(value).sort()
|
404
|
+
const keys = Object.keys(value).sort();
|
418
405
|
|
419
|
-
if (this.command ===
|
406
|
+
if (this.command === "first-key") {
|
420
407
|
key = 0;
|
421
|
-
} else if (this.command ===
|
408
|
+
} else if (this.command === "last-key") {
|
422
409
|
key = keys.length - 1;
|
423
410
|
} else {
|
424
|
-
|
425
411
|
key = validateInteger(parseInt(args.shift()));
|
426
412
|
|
427
|
-
if (this.command ===
|
413
|
+
if (this.command === "nth-last-key") {
|
428
414
|
key = keys.length - key - 1;
|
429
415
|
}
|
430
416
|
}
|
431
417
|
|
432
|
-
defaultValue =
|
418
|
+
defaultValue = args.shift() || "";
|
433
419
|
|
434
420
|
let useKey = keys?.[key];
|
435
421
|
|
@@ -439,18 +425,16 @@ function transform(value) {
|
|
439
425
|
|
440
426
|
return defaultValue;
|
441
427
|
|
442
|
-
|
443
|
-
case
|
444
|
-
case
|
445
|
-
case 'index':
|
446
|
-
|
428
|
+
case "key":
|
429
|
+
case "property":
|
430
|
+
case "index":
|
447
431
|
key = args.shift() || undefined;
|
448
432
|
|
449
433
|
if (key === undefined) {
|
450
|
-
throw new Error("missing key parameter")
|
434
|
+
throw new Error("missing key parameter");
|
451
435
|
}
|
452
436
|
|
453
|
-
defaultValue =
|
437
|
+
defaultValue = args.shift() || undefined;
|
454
438
|
|
455
439
|
if (value instanceof Map) {
|
456
440
|
if (!value.has(key)) {
|
@@ -460,7 +444,6 @@ function transform(value) {
|
|
460
444
|
}
|
461
445
|
|
462
446
|
if (isObject(value) || isArray(value)) {
|
463
|
-
|
464
447
|
if (value?.[key]) {
|
465
448
|
return value?.[key];
|
466
449
|
}
|
@@ -468,22 +451,20 @@ function transform(value) {
|
|
468
451
|
return defaultValue;
|
469
452
|
}
|
470
453
|
|
471
|
-
throw new Error("type not supported")
|
472
|
-
|
473
|
-
case 'path-exists':
|
454
|
+
throw new Error("type not supported");
|
474
455
|
|
456
|
+
case "path-exists":
|
475
457
|
key = args.shift();
|
476
458
|
if (key === undefined) {
|
477
|
-
throw new Error("missing key parameter")
|
459
|
+
throw new Error("missing key parameter");
|
478
460
|
}
|
479
461
|
|
480
462
|
return new Pathfinder(value).exists(key);
|
481
463
|
|
482
|
-
case
|
483
|
-
|
464
|
+
case "path":
|
484
465
|
key = args.shift();
|
485
466
|
if (key === undefined) {
|
486
|
-
throw new Error("missing key parameter")
|
467
|
+
throw new Error("missing key parameter");
|
487
468
|
}
|
488
469
|
|
489
470
|
let pf = new Pathfinder(value);
|
@@ -494,9 +475,7 @@ function transform(value) {
|
|
494
475
|
|
495
476
|
return pf.getVia(key);
|
496
477
|
|
497
|
-
|
498
|
-
case 'substring':
|
499
|
-
|
478
|
+
case "substring":
|
500
479
|
validateString(value);
|
501
480
|
|
502
481
|
let start = parseInt(args[0]) || 0;
|
@@ -504,11 +483,11 @@ function transform(value) {
|
|
504
483
|
|
505
484
|
return value.substring(start, end);
|
506
485
|
|
507
|
-
case
|
486
|
+
case "nop":
|
508
487
|
return value;
|
509
488
|
|
510
|
-
case
|
511
|
-
case
|
489
|
+
case "??":
|
490
|
+
case "default":
|
512
491
|
if (value !== undefined && value !== null) {
|
513
492
|
return value;
|
514
493
|
}
|
@@ -516,34 +495,39 @@ function transform(value) {
|
|
516
495
|
defaultValue = args.shift();
|
517
496
|
let defaultType = args.shift();
|
518
497
|
if (defaultType === undefined) {
|
519
|
-
defaultType =
|
498
|
+
defaultType = "string";
|
520
499
|
}
|
521
500
|
|
522
501
|
switch (defaultType) {
|
523
|
-
case
|
524
|
-
case
|
502
|
+
case "int":
|
503
|
+
case "integer":
|
525
504
|
return parseInt(defaultValue);
|
526
|
-
case
|
505
|
+
case "float":
|
527
506
|
return parseFloat(defaultValue);
|
528
|
-
case
|
529
|
-
return undefined
|
530
|
-
case
|
531
|
-
case
|
532
|
-
defaultValue = defaultValue.toLowerCase()
|
533
|
-
return (
|
534
|
-
|
535
|
-
|
507
|
+
case "undefined":
|
508
|
+
return undefined;
|
509
|
+
case "bool":
|
510
|
+
case "boolean":
|
511
|
+
defaultValue = defaultValue.toLowerCase();
|
512
|
+
return (
|
513
|
+
(defaultValue !== "undefined" &&
|
514
|
+
defaultValue !== "" &&
|
515
|
+
defaultValue !== "off" &&
|
516
|
+
defaultValue !== "false" &&
|
517
|
+
defaultValue !== "false") ||
|
518
|
+
defaultValue === "on" ||
|
519
|
+
defaultValue === "true" ||
|
520
|
+
defaultValue === "true"
|
521
|
+
);
|
522
|
+
case "string":
|
523
|
+
return `${defaultValue}`;
|
536
524
|
case "object":
|
537
525
|
return JSON.parse(atob(defaultValue));
|
538
526
|
}
|
539
527
|
|
540
|
-
throw new Error("type not supported")
|
541
|
-
|
528
|
+
throw new Error("type not supported");
|
542
529
|
|
543
530
|
default:
|
544
|
-
throw new Error(
|
531
|
+
throw new Error(`unknown command ${this.command}`);
|
545
532
|
}
|
546
|
-
|
547
|
-
return value;
|
548
533
|
}
|
549
|
-
|
package/source/dom/assembler.mjs
CHANGED
@@ -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 {getGlobalFunction} from "../types/global.mjs";
|
10
|
-
import {ProxyObserver} from "../types/proxyobserver.mjs";
|
11
|
-
import {validateInstance, validateString} from "../types/validate.mjs";
|
8
|
+
import { Base } from "../types/base.mjs";
|
9
|
+
import { getGlobalFunction } from "../types/global.mjs";
|
10
|
+
import { ProxyObserver } from "../types/proxyobserver.mjs";
|
11
|
+
import { validateInstance, validateString } from "../types/validate.mjs";
|
12
12
|
|
13
|
-
export {ATTRIBUTEPREFIX,Assembler}
|
13
|
+
export { ATTRIBUTEPREFIX, Assembler };
|
14
14
|
|
15
15
|
/**
|
16
16
|
* attribute prefix
|
@@ -30,7 +30,6 @@ const ATTRIBUTEPREFIX = "data-monster-";
|
|
30
30
|
* @summary Allows you to build an html fragment
|
31
31
|
*/
|
32
32
|
class Assembler extends Base {
|
33
|
-
|
34
33
|
/**
|
35
34
|
* @param {DocumentFragment} fragment
|
36
35
|
* @throws {TypeError} value is not an instance of
|
@@ -40,7 +39,7 @@ class Assembler extends Base {
|
|
40
39
|
constructor(fragment) {
|
41
40
|
super();
|
42
41
|
this.attributePrefix = ATTRIBUTEPREFIX;
|
43
|
-
validateInstance(fragment, getGlobalFunction(
|
42
|
+
validateInstance(fragment, getGlobalFunction("DocumentFragment"));
|
44
43
|
this.fragment = fragment;
|
45
44
|
}
|
46
45
|
|
@@ -71,7 +70,6 @@ class Assembler extends Base {
|
|
71
70
|
* @throws {TypeError} value is not an instance of
|
72
71
|
*/
|
73
72
|
createDocumentFragment(data) {
|
74
|
-
|
75
73
|
if (data === undefined) {
|
76
74
|
data = new ProxyObserver({});
|
77
75
|
}
|
@@ -80,5 +78,4 @@ class Assembler extends Base {
|
|
80
78
|
let fragment = this.fragment.cloneNode(true);
|
81
79
|
return fragment;
|
82
80
|
}
|
83
|
-
|
84
81
|
}
|