@schukai/monster 3.4.2 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/example/i18n/providers/embed.mjs +5 -0
- 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 +17 -21
- 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 +41 -10
- 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 +115 -0
- package/source/i18n/providers/fetch.mjs +33 -38
- package/source/i18n/translations.mjs +16 -20
- 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/dom/locale.mjs +15 -0
- package/test/cases/i18n/providers/embed.mjs +72 -0
- package/test/cases/monster.mjs +1 -1
|
@@ -5,46 +5,45 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {internalSymbol} from "../constants.mjs";
|
|
9
|
-
import {extend} from "../data/extend.mjs";
|
|
10
|
-
import {Pipe} from "../data/pipe.mjs";
|
|
8
|
+
import { internalSymbol } from "../constants.mjs";
|
|
9
|
+
import { extend } from "../data/extend.mjs";
|
|
10
|
+
import { Pipe } from "../data/pipe.mjs";
|
|
11
11
|
|
|
12
|
-
import {BaseWithOptions} from "../types/basewithoptions.mjs";
|
|
13
|
-
import {isObject, isString} from "../types/is.mjs";
|
|
14
|
-
import {validateArray, validateString} from "../types/validate.mjs";
|
|
12
|
+
import { BaseWithOptions } from "../types/basewithoptions.mjs";
|
|
13
|
+
import { isObject, isString } from "../types/is.mjs";
|
|
14
|
+
import { validateArray, validateString } from "../types/validate.mjs";
|
|
15
15
|
|
|
16
|
-
export {Formatter}
|
|
16
|
+
export { Formatter };
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @private
|
|
20
20
|
* @type {symbol}
|
|
21
21
|
*/
|
|
22
|
-
const internalObjectSymbol = Symbol(
|
|
22
|
+
const internalObjectSymbol = Symbol("internalObject");
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* @private
|
|
26
26
|
* @type {symbol}
|
|
27
27
|
*/
|
|
28
|
-
const watchdogSymbol = Symbol(
|
|
28
|
+
const watchdogSymbol = Symbol("watchdog");
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* @private
|
|
32
32
|
* @type {symbol}
|
|
33
33
|
*/
|
|
34
|
-
const markerOpenIndexSymbol = Symbol(
|
|
34
|
+
const markerOpenIndexSymbol = Symbol("markerOpenIndex");
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* @private
|
|
38
38
|
* @type {symbol}
|
|
39
39
|
*/
|
|
40
|
-
const markerCloseIndexSymbol = Symbol(
|
|
40
|
+
const markerCloseIndexSymbol = Symbol("markercloseIndex");
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* @private
|
|
44
44
|
* @type {symbol}
|
|
45
45
|
*/
|
|
46
|
-
const workingDataSymbol = Symbol(
|
|
47
|
-
|
|
46
|
+
const workingDataSymbol = Symbol("workingData");
|
|
48
47
|
|
|
49
48
|
/**
|
|
50
49
|
* Messages can be formatted with the formatter. To do this, an object with the values must be passed to the formatter. The message can then contain placeholders.
|
|
@@ -109,8 +108,7 @@ const workingDataSymbol = Symbol('workingData');
|
|
|
109
108
|
* @copyright schukai GmbH
|
|
110
109
|
* @memberOf Monster.Text
|
|
111
110
|
*/
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
class Formatter extends BaseWithOptions {
|
|
114
112
|
/**
|
|
115
113
|
* Default values for the markers are `${` and `}`
|
|
116
114
|
*
|
|
@@ -119,7 +117,7 @@ const workingDataSymbol = Symbol('workingData');
|
|
|
119
117
|
*/
|
|
120
118
|
constructor(object, options) {
|
|
121
119
|
super(options);
|
|
122
|
-
this[internalObjectSymbol] = object || {}
|
|
120
|
+
this[internalObjectSymbol] = object || {};
|
|
123
121
|
this[markerOpenIndexSymbol] = 0;
|
|
124
122
|
this[markerCloseIndexSymbol] = 0;
|
|
125
123
|
}
|
|
@@ -136,18 +134,17 @@ const workingDataSymbol = Symbol('workingData');
|
|
|
136
134
|
get defaults() {
|
|
137
135
|
return extend({}, super.defaults, {
|
|
138
136
|
marker: {
|
|
139
|
-
open: [
|
|
140
|
-
close: [
|
|
137
|
+
open: ["${"],
|
|
138
|
+
close: ["}"],
|
|
141
139
|
},
|
|
142
140
|
parameter: {
|
|
143
|
-
delimiter:
|
|
144
|
-
assignment:
|
|
141
|
+
delimiter: "::",
|
|
142
|
+
assignment: "=",
|
|
145
143
|
},
|
|
146
144
|
callbacks: {},
|
|
147
|
-
})
|
|
145
|
+
});
|
|
148
146
|
}
|
|
149
147
|
|
|
150
|
-
|
|
151
148
|
/**
|
|
152
149
|
* Set new Parameter Character
|
|
153
150
|
*
|
|
@@ -166,13 +163,12 @@ const workingDataSymbol = Symbol('workingData');
|
|
|
166
163
|
* @throws {TypeError} value is not a string
|
|
167
164
|
*/
|
|
168
165
|
setParameterChars(delimiter, assignment) {
|
|
169
|
-
|
|
170
166
|
if (delimiter !== undefined) {
|
|
171
|
-
this[internalSymbol][
|
|
167
|
+
this[internalSymbol]["parameter"]["delimiter"] = validateString(delimiter);
|
|
172
168
|
}
|
|
173
169
|
|
|
174
170
|
if (assignment !== undefined) {
|
|
175
|
-
this[internalSymbol][
|
|
171
|
+
this[internalSymbol]["parameter"]["assignment"] = validateString(assignment);
|
|
176
172
|
}
|
|
177
173
|
|
|
178
174
|
return this;
|
|
@@ -196,7 +192,6 @@ const workingDataSymbol = Symbol('workingData');
|
|
|
196
192
|
* @throws {TypeError} value is not a string
|
|
197
193
|
*/
|
|
198
194
|
setMarker(open, close) {
|
|
199
|
-
|
|
200
195
|
if (close === undefined) {
|
|
201
196
|
close = open;
|
|
202
197
|
}
|
|
@@ -204,8 +199,8 @@ const workingDataSymbol = Symbol('workingData');
|
|
|
204
199
|
if (isString(open)) open = [open];
|
|
205
200
|
if (isString(close)) close = [close];
|
|
206
201
|
|
|
207
|
-
this[internalSymbol][
|
|
208
|
-
this[internalSymbol][
|
|
202
|
+
this[internalSymbol]["marker"]["open"] = validateArray(open);
|
|
203
|
+
this[internalSymbol]["marker"]["close"] = validateArray(close);
|
|
209
204
|
return this;
|
|
210
205
|
}
|
|
211
206
|
|
|
@@ -223,7 +218,6 @@ const workingDataSymbol = Symbol('workingData');
|
|
|
223
218
|
this[workingDataSymbol] = {};
|
|
224
219
|
return format.call(this, text);
|
|
225
220
|
}
|
|
226
|
-
|
|
227
221
|
}
|
|
228
222
|
|
|
229
223
|
/**
|
|
@@ -235,28 +229,28 @@ function format(text) {
|
|
|
235
229
|
|
|
236
230
|
self[watchdogSymbol]++;
|
|
237
231
|
if (this[watchdogSymbol] > 20) {
|
|
238
|
-
throw new Error(
|
|
232
|
+
throw new Error("too deep nesting");
|
|
239
233
|
}
|
|
240
234
|
|
|
241
|
-
let openMarker = self[internalSymbol][
|
|
242
|
-
let closeMarker = self[internalSymbol][
|
|
235
|
+
let openMarker = self[internalSymbol]["marker"]["open"]?.[this[markerOpenIndexSymbol]];
|
|
236
|
+
let closeMarker = self[internalSymbol]["marker"]["close"]?.[this[markerCloseIndexSymbol]];
|
|
243
237
|
|
|
244
238
|
// contains no placeholders
|
|
245
239
|
if (text.indexOf(openMarker) === -1 || text.indexOf(closeMarker) === -1) {
|
|
246
240
|
return text;
|
|
247
241
|
}
|
|
248
242
|
|
|
249
|
-
let result = tokenize.call(this, validateString(text), openMarker, closeMarker)
|
|
243
|
+
let result = tokenize.call(this, validateString(text), openMarker, closeMarker);
|
|
250
244
|
|
|
251
|
-
if (self[internalSymbol][
|
|
245
|
+
if (self[internalSymbol]["marker"]["open"]?.[this[markerOpenIndexSymbol] + 1]) {
|
|
252
246
|
this[markerOpenIndexSymbol]++;
|
|
253
247
|
}
|
|
254
248
|
|
|
255
|
-
if (self[internalSymbol][
|
|
249
|
+
if (self[internalSymbol]["marker"]["close"]?.[this[markerCloseIndexSymbol] + 1]) {
|
|
256
250
|
this[markerCloseIndexSymbol]++;
|
|
257
251
|
}
|
|
258
252
|
|
|
259
|
-
result = format.call(self, result)
|
|
253
|
+
result = format.call(self, result);
|
|
260
254
|
|
|
261
255
|
return result;
|
|
262
256
|
}
|
|
@@ -273,20 +267,19 @@ function tokenize(text, openMarker, closeMarker) {
|
|
|
273
267
|
|
|
274
268
|
let formatted = [];
|
|
275
269
|
|
|
276
|
-
const parameterAssignment = self[internalSymbol][
|
|
277
|
-
const parameterDelimiter = self[internalSymbol][
|
|
278
|
-
const callbacks = self[internalSymbol][
|
|
270
|
+
const parameterAssignment = self[internalSymbol]["parameter"]["assignment"];
|
|
271
|
+
const parameterDelimiter = self[internalSymbol]["parameter"]["delimiter"];
|
|
272
|
+
const callbacks = self[internalSymbol]["callbacks"];
|
|
279
273
|
|
|
280
274
|
while (true) {
|
|
281
|
-
|
|
282
275
|
let startIndex = text.indexOf(openMarker);
|
|
283
|
-
// no marker
|
|
276
|
+
// no marker
|
|
284
277
|
if (startIndex === -1) {
|
|
285
278
|
formatted.push(text);
|
|
286
279
|
break;
|
|
287
280
|
} else if (startIndex > 0) {
|
|
288
|
-
formatted.push(text.substring(0, startIndex))
|
|
289
|
-
text = text.substring(startIndex)
|
|
281
|
+
formatted.push(text.substring(0, startIndex));
|
|
282
|
+
text = text.substring(startIndex);
|
|
290
283
|
}
|
|
291
284
|
|
|
292
285
|
let endIndex = text.substring(openMarker.length).indexOf(closeMarker);
|
|
@@ -296,15 +289,14 @@ function tokenize(text, openMarker, closeMarker) {
|
|
|
296
289
|
insideStartIndex += openMarker.length;
|
|
297
290
|
if (insideStartIndex < endIndex) {
|
|
298
291
|
let result = tokenize.call(self, text.substring(insideStartIndex), openMarker, closeMarker);
|
|
299
|
-
text = text.substring(0, insideStartIndex) + result
|
|
292
|
+
text = text.substring(0, insideStartIndex) + result;
|
|
300
293
|
endIndex = text.substring(openMarker.length).indexOf(closeMarker);
|
|
301
294
|
if (endIndex !== -1) endIndex += openMarker.length;
|
|
302
295
|
}
|
|
303
296
|
}
|
|
304
297
|
|
|
305
298
|
if (endIndex === -1) {
|
|
306
|
-
throw new Error("syntax error in formatter template")
|
|
307
|
-
return;
|
|
299
|
+
throw new Error("syntax error in formatter template");
|
|
308
300
|
}
|
|
309
301
|
|
|
310
302
|
let key = text.substring(openMarker.length, endIndex);
|
|
@@ -318,15 +310,13 @@ function tokenize(text, openMarker, closeMarker) {
|
|
|
318
310
|
self[workingDataSymbol][k] = v;
|
|
319
311
|
}
|
|
320
312
|
|
|
321
|
-
const t1 = key.split(
|
|
322
|
-
const t2 = t1.split(
|
|
323
|
-
const t3 = t2.split(
|
|
324
|
-
let prefix = self[workingDataSymbol]?.[t3] ?
|
|
313
|
+
const t1 = key.split("|").shift().trim(); // pipe symbol
|
|
314
|
+
const t2 = t1.split("::").shift().trim(); // key value delimiter
|
|
315
|
+
const t3 = t2.split(".").shift().trim(); // path delimiter
|
|
316
|
+
let prefix = self[workingDataSymbol]?.[t3] ? "path:" : "static:";
|
|
325
317
|
|
|
326
318
|
let command = "";
|
|
327
|
-
if (prefix && key.indexOf(prefix) !== 0
|
|
328
|
-
&& key.indexOf('path:') !== 0
|
|
329
|
-
&& key.indexOf('static:') !== 0) {
|
|
319
|
+
if (prefix && key.indexOf(prefix) !== 0 && key.indexOf("path:") !== 0 && key.indexOf("static:") !== 0) {
|
|
330
320
|
command = prefix;
|
|
331
321
|
}
|
|
332
322
|
|
|
@@ -343,8 +333,7 @@ function tokenize(text, openMarker, closeMarker) {
|
|
|
343
333
|
formatted.push(validateString(pipe.run(self[workingDataSymbol])));
|
|
344
334
|
|
|
345
335
|
text = text.substring(endIndex + closeMarker.length);
|
|
346
|
-
|
|
347
336
|
}
|
|
348
337
|
|
|
349
|
-
return formatted.join(
|
|
338
|
+
return formatted.join("");
|
|
350
339
|
}
|
package/source/types/base.mjs
CHANGED
|
@@ -5,24 +5,23 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {instanceSymbol} from "../constants.mjs";
|
|
9
|
-
|
|
10
|
-
export {Base}
|
|
8
|
+
import { instanceSymbol } from "../constants.mjs";
|
|
11
9
|
|
|
10
|
+
export { Base };
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* This is the base class from which all monster classes are derived.
|
|
15
|
-
*
|
|
14
|
+
*
|
|
16
15
|
* This class has besides a `toString` which returns the json representation of the object
|
|
17
16
|
* also a functionality to check if an object is an instance of a class.
|
|
18
|
-
*
|
|
19
|
-
* Therefor the class has a static method ` [Symbol.hasInstance](that)` which returns true if the object
|
|
20
|
-
* is an instance of the class.
|
|
17
|
+
*
|
|
18
|
+
* Therefor the class has a static method ` [Symbol.hasInstance](that)` which returns true if the object
|
|
19
|
+
* is an instance of the class.
|
|
21
20
|
* F
|
|
22
21
|
* @see [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance](developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
|
|
23
22
|
*
|
|
24
23
|
* Derived classes should implement a static getter `instanceSymbol` which returns a unique symbol.
|
|
25
|
-
*
|
|
24
|
+
*
|
|
26
25
|
* ```javascript
|
|
27
26
|
* static get [instanceSymbol]() {
|
|
28
27
|
* return Symbol.for("@schukai/monster/types/base");
|
|
@@ -37,14 +36,13 @@ export {Base}
|
|
|
37
36
|
* @memberOf Monster.Types
|
|
38
37
|
*/
|
|
39
38
|
class Base extends Object {
|
|
40
|
-
|
|
41
39
|
/**
|
|
42
40
|
*
|
|
43
41
|
* @returns {string}
|
|
44
42
|
*/
|
|
45
43
|
toString() {
|
|
46
44
|
return JSON.stringify(this);
|
|
47
|
-
}
|
|
45
|
+
}
|
|
48
46
|
|
|
49
47
|
/**
|
|
50
48
|
* This method is called by the `instanceof` operator.
|
|
@@ -62,13 +60,16 @@ class Base extends Object {
|
|
|
62
60
|
* @since 2.1.0
|
|
63
61
|
*/
|
|
64
62
|
static [Symbol.hasInstance](that) {
|
|
65
|
-
|
|
66
63
|
if (that === undefined || that === null || (typeof that !== "object" && typeof that !== "function")) {
|
|
67
64
|
return false;
|
|
68
65
|
}
|
|
69
66
|
|
|
70
|
-
const thatClass = Object.getPrototypeOf(that)
|
|
71
|
-
if (
|
|
67
|
+
const thatClass = Object.getPrototypeOf(that);
|
|
68
|
+
if (
|
|
69
|
+
thatClass === undefined ||
|
|
70
|
+
thatClass === null ||
|
|
71
|
+
(typeof thatClass !== "object" && typeof thatClass !== "function")
|
|
72
|
+
) {
|
|
72
73
|
return false;
|
|
73
74
|
}
|
|
74
75
|
|
|
@@ -76,24 +77,20 @@ class Base extends Object {
|
|
|
76
77
|
return true;
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
|
|
80
80
|
// this call the static method of the super class, if there is one
|
|
81
81
|
return super[Symbol.hasInstance](that);
|
|
82
|
-
|
|
83
82
|
}
|
|
84
|
-
|
|
85
83
|
}
|
|
86
84
|
|
|
87
85
|
/**
|
|
88
86
|
* this function checks if the class has a static getter `instanceSymbol` and if the value of this getter is equal to the
|
|
89
|
-
*
|
|
87
|
+
*
|
|
90
88
|
* @private
|
|
91
89
|
* @param obj
|
|
92
90
|
* @returns {boolean|any|boolean}
|
|
93
91
|
* @since 2.1.0
|
|
94
92
|
*/
|
|
95
93
|
function checkInstanceSymbol(obj) {
|
|
96
|
-
|
|
97
94
|
if (this.hasOwnProperty(instanceSymbol) === false) {
|
|
98
95
|
return false;
|
|
99
96
|
}
|
|
@@ -109,23 +106,16 @@ function checkInstanceSymbol(obj) {
|
|
|
109
106
|
|
|
110
107
|
const symbol = proto[instanceSymbol];
|
|
111
108
|
if (symbol === undefined) {
|
|
112
|
-
|
|
113
109
|
if (obj.__proto__) {
|
|
114
110
|
return checkInstanceSymbol(obj.__proto__);
|
|
115
111
|
} else {
|
|
116
112
|
return false;
|
|
117
113
|
}
|
|
118
|
-
|
|
119
114
|
}
|
|
120
115
|
|
|
121
116
|
if (symbol === this[instanceSymbol]) {
|
|
122
117
|
return true;
|
|
123
118
|
}
|
|
124
|
-
|
|
125
|
-
return checkInstanceSymbol.apply(this, [obj.__proto__]);
|
|
126
|
-
|
|
127
119
|
|
|
120
|
+
return checkInstanceSymbol.apply(this, [obj.__proto__]);
|
|
128
121
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {internalSymbol} from "../constants.mjs";
|
|
9
|
-
import {extend} from "../data/extend.mjs";
|
|
10
|
-
import {Pathfinder} from "../data/pathfinder.mjs";
|
|
11
|
-
import {Base} from "./base.mjs";
|
|
12
|
-
import {validateObject} from "./validate.mjs";
|
|
8
|
+
import { internalSymbol } from "../constants.mjs";
|
|
9
|
+
import { extend } from "../data/extend.mjs";
|
|
10
|
+
import { Pathfinder } from "../data/pathfinder.mjs";
|
|
11
|
+
import { Base } from "./base.mjs";
|
|
12
|
+
import { validateObject } from "./validate.mjs";
|
|
13
13
|
|
|
14
|
-
export {BaseWithOptions}
|
|
14
|
+
export { BaseWithOptions };
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* This is the base class with options from which some monster classes are derived.
|
|
@@ -28,7 +28,6 @@ export {BaseWithOptions}
|
|
|
28
28
|
* @memberOf Monster.Types
|
|
29
29
|
*/
|
|
30
30
|
class BaseWithOptions extends Base {
|
|
31
|
-
|
|
32
31
|
/**
|
|
33
32
|
*
|
|
34
33
|
* @param {object} options
|
|
@@ -41,7 +40,6 @@ class BaseWithOptions extends Base {
|
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
this[internalSymbol] = extend({}, this.defaults, validateObject(options));
|
|
44
|
-
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
/**
|
|
@@ -61,7 +59,7 @@ class BaseWithOptions extends Base {
|
|
|
61
59
|
* @return {object}
|
|
62
60
|
*/
|
|
63
61
|
get defaults() {
|
|
64
|
-
return {}
|
|
62
|
+
return {};
|
|
65
63
|
}
|
|
66
64
|
|
|
67
65
|
/**
|
|
@@ -77,13 +75,9 @@ class BaseWithOptions extends Base {
|
|
|
77
75
|
|
|
78
76
|
try {
|
|
79
77
|
value = new Pathfinder(this[internalSymbol]).getVia(path);
|
|
80
|
-
} catch (e) {
|
|
81
|
-
|
|
82
|
-
}
|
|
78
|
+
} catch (e) {}
|
|
83
79
|
|
|
84
80
|
if (value === undefined) return defaultValue;
|
|
85
81
|
return value;
|
|
86
82
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
83
|
}
|
package/source/types/binary.mjs
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {validateString} from "./validate.mjs";
|
|
8
|
+
import { validateString } from "./validate.mjs";
|
|
9
9
|
|
|
10
|
-
export {toBinary, fromBinary}
|
|
10
|
+
export { toBinary, fromBinary };
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* You can call the function via the monster namespace `Monster.Types.toBinary()`.
|
|
@@ -26,7 +26,7 @@ function toBinary(string) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const charCodes = new Uint8Array(codeUnits.buffer);
|
|
29
|
-
let result =
|
|
29
|
+
let result = "";
|
|
30
30
|
|
|
31
31
|
for (let i = 0; i < charCodes.byteLength; i++) {
|
|
32
32
|
result += String.fromCharCode(charCodes[i]);
|
|
@@ -51,10 +51,9 @@ function fromBinary(binary) {
|
|
|
51
51
|
bytes[i] = binary.charCodeAt(i);
|
|
52
52
|
}
|
|
53
53
|
const charCodes = new Uint16Array(bytes.buffer);
|
|
54
|
-
let result =
|
|
54
|
+
let result = "";
|
|
55
55
|
for (let i = 0; i < charCodes.length; i++) {
|
|
56
56
|
result += String.fromCharCode(charCodes[i]);
|
|
57
57
|
}
|
|
58
58
|
return result;
|
|
59
59
|
}
|
|
60
|
-
|
package/source/types/dataurl.mjs
CHANGED
|
@@ -5,18 +5,18 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {Base} from "./base.mjs";
|
|
9
|
-
import {isString} from "./is.mjs";
|
|
10
|
-
import {MediaType, parseMediaType} from "./mediatype.mjs";
|
|
11
|
-
import {validateBoolean, validateInstance, validateString} from "./validate.mjs";
|
|
12
|
-
import {instanceSymbol} from
|
|
13
|
-
export {DataUrl, parseDataURL}
|
|
8
|
+
import { Base } from "./base.mjs";
|
|
9
|
+
import { isString } from "./is.mjs";
|
|
10
|
+
import { MediaType, parseMediaType } from "./mediatype.mjs";
|
|
11
|
+
import { validateBoolean, validateInstance, validateString } from "./validate.mjs";
|
|
12
|
+
import { instanceSymbol } from "../constants.mjs";
|
|
13
|
+
export { DataUrl, parseDataURL };
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @private
|
|
17
17
|
* @type {symbol}
|
|
18
18
|
*/
|
|
19
|
-
const internal = Symbol(
|
|
19
|
+
const internal = Symbol("internal");
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* You can create an object via the monster namespace `new Monster.Types.DataUrl()`.
|
|
@@ -29,7 +29,6 @@ const internal = Symbol('internal');
|
|
|
29
29
|
* @see https://datatracker.ietf.org/doc/html/rfc2397
|
|
30
30
|
*/
|
|
31
31
|
class DataUrl extends Base {
|
|
32
|
-
|
|
33
32
|
/**
|
|
34
33
|
*
|
|
35
34
|
* @param {String} content
|
|
@@ -46,10 +45,8 @@ class DataUrl extends Base {
|
|
|
46
45
|
this[internal] = {
|
|
47
46
|
content: validateString(content),
|
|
48
47
|
mediatype: validateInstance(mediatype, MediaType),
|
|
49
|
-
base64: validateBoolean(base64 === undefined ? true : base64)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
base64: validateBoolean(base64 === undefined ? true : base64),
|
|
49
|
+
};
|
|
53
50
|
}
|
|
54
51
|
|
|
55
52
|
/**
|
|
@@ -61,7 +58,6 @@ class DataUrl extends Base {
|
|
|
61
58
|
return Symbol.for("@schukai/monster/types/data-url");
|
|
62
59
|
}
|
|
63
60
|
|
|
64
|
-
|
|
65
61
|
get content() {
|
|
66
62
|
return this[internal].base64 ? atob(this[internal].content) : this[internal].content;
|
|
67
63
|
}
|
|
@@ -70,25 +66,22 @@ class DataUrl extends Base {
|
|
|
70
66
|
return this[internal].mediatype;
|
|
71
67
|
}
|
|
72
68
|
|
|
73
|
-
|
|
74
69
|
/**
|
|
75
70
|
*
|
|
76
71
|
* @return {string}
|
|
77
72
|
* @see https://datatracker.ietf.org/doc/html/rfc2397
|
|
78
73
|
*/
|
|
79
74
|
toString() {
|
|
80
|
-
|
|
81
75
|
let content = this[internal].content;
|
|
82
76
|
|
|
83
77
|
if (this[internal].base64 === true) {
|
|
84
|
-
content =
|
|
78
|
+
content = `;base64,${content}`;
|
|
85
79
|
} else {
|
|
86
|
-
content =
|
|
80
|
+
content = `,${encodeURIComponent(content)}`;
|
|
87
81
|
}
|
|
88
82
|
|
|
89
|
-
return
|
|
83
|
+
return `data:${this[internal].mediatype.toString()}${content}`;
|
|
90
84
|
}
|
|
91
|
-
|
|
92
85
|
}
|
|
93
86
|
|
|
94
87
|
/**
|
|
@@ -112,31 +105,30 @@ class DataUrl extends Base {
|
|
|
112
105
|
* @memberOf Monster.Types
|
|
113
106
|
*/
|
|
114
107
|
function parseDataURL(dataurl) {
|
|
115
|
-
|
|
116
108
|
validateString(dataurl);
|
|
117
109
|
|
|
118
110
|
dataurl = dataurl.trim();
|
|
119
111
|
|
|
120
|
-
if (dataurl.substring(0, 5) !==
|
|
121
|
-
throw new TypeError(
|
|
112
|
+
if (dataurl.substring(0, 5) !== "data:") {
|
|
113
|
+
throw new TypeError("incorrect or missing data protocol");
|
|
122
114
|
}
|
|
123
115
|
|
|
124
116
|
dataurl = dataurl.substring(5);
|
|
125
117
|
|
|
126
|
-
let p = dataurl.indexOf(
|
|
118
|
+
let p = dataurl.indexOf(",");
|
|
127
119
|
if (p === -1) {
|
|
128
|
-
throw new TypeError(
|
|
120
|
+
throw new TypeError("malformed data url");
|
|
129
121
|
}
|
|
130
122
|
|
|
131
123
|
let content = dataurl.substring(p + 1);
|
|
132
124
|
let mediatypeAndBase64 = dataurl.substring(0, p).trim();
|
|
133
|
-
let mediatype =
|
|
125
|
+
let mediatype = "text/plain;charset=US-ASCII";
|
|
134
126
|
let base64Flag = false;
|
|
135
127
|
|
|
136
128
|
if (mediatypeAndBase64 !== "") {
|
|
137
129
|
mediatype = mediatypeAndBase64;
|
|
138
|
-
if (mediatypeAndBase64.endsWith(
|
|
139
|
-
let i = mediatypeAndBase64.lastIndexOf(
|
|
130
|
+
if (mediatypeAndBase64.endsWith("base64")) {
|
|
131
|
+
let i = mediatypeAndBase64.lastIndexOf(";");
|
|
140
132
|
mediatype = mediatypeAndBase64.substring(0, i);
|
|
141
133
|
base64Flag = true;
|
|
142
134
|
} else {
|
package/source/types/global.mjs
CHANGED
|
@@ -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,10 +5,9 @@
|
|
|
7
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
8
6
|
*/
|
|
9
7
|
|
|
8
|
+
import { validateFunction, validateObject, validateString } from "./validate.mjs";
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export {getGlobal, getGlobalObject, getGlobalFunction}
|
|
10
|
+
export { getGlobal, getGlobalObject, getGlobalFunction };
|
|
14
11
|
|
|
15
12
|
/**
|
|
16
13
|
* @type {objec}
|
|
@@ -23,28 +20,27 @@ let globalReference;
|
|
|
23
20
|
* @throws {Error} unsupported environment.
|
|
24
21
|
*/
|
|
25
22
|
(function () {
|
|
26
|
-
|
|
27
|
-
if (typeof globalThis === 'object') {
|
|
23
|
+
if (typeof globalThis === "object") {
|
|
28
24
|
globalReference = globalThis;
|
|
29
25
|
return;
|
|
30
26
|
}
|
|
31
27
|
|
|
32
|
-
if (typeof self !==
|
|
28
|
+
if (typeof self !== "undefined") {
|
|
33
29
|
globalReference = self;
|
|
34
30
|
return;
|
|
35
|
-
} else if (typeof window !==
|
|
31
|
+
} else if (typeof window !== "undefined") {
|
|
36
32
|
globalReference = window;
|
|
37
33
|
return;
|
|
38
34
|
}
|
|
39
35
|
|
|
40
|
-
Object.defineProperty(Object.prototype,
|
|
36
|
+
Object.defineProperty(Object.prototype, "__monster__", {
|
|
41
37
|
get: function () {
|
|
42
38
|
return this;
|
|
43
39
|
},
|
|
44
|
-
configurable: true
|
|
40
|
+
configurable: true,
|
|
45
41
|
});
|
|
46
42
|
|
|
47
|
-
if (typeof __monster__ ===
|
|
43
|
+
if (typeof __monster__ === "object") {
|
|
48
44
|
__monster__.globalThis = __monster__;
|
|
49
45
|
delete Object.prototype.__monster__;
|
|
50
46
|
|
|
@@ -53,15 +49,11 @@ let globalReference;
|
|
|
53
49
|
}
|
|
54
50
|
|
|
55
51
|
try {
|
|
56
|
-
globalReference = Function(
|
|
57
|
-
} catch (e) {
|
|
58
|
-
|
|
59
|
-
}
|
|
52
|
+
globalReference = Function("return this")();
|
|
53
|
+
} catch (e) {}
|
|
60
54
|
|
|
61
|
-
throw new Error("unsupported environment.")
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}());
|
|
55
|
+
throw new Error("unsupported environment.");
|
|
56
|
+
})();
|
|
65
57
|
|
|
66
58
|
/**
|
|
67
59
|
* Return globalThis
|
|
@@ -112,7 +104,7 @@ function getGlobal() {
|
|
|
112
104
|
function getGlobalObject(name) {
|
|
113
105
|
validateString(name);
|
|
114
106
|
let o = globalReference?.[name];
|
|
115
|
-
if (typeof o ===
|
|
107
|
+
if (typeof o === "undefined") throw new Error(`the object ${name} is not defined`);
|
|
116
108
|
validateObject(o);
|
|
117
109
|
return o;
|
|
118
110
|
}
|
|
@@ -150,11 +142,7 @@ function getGlobalObject(name) {
|
|
|
150
142
|
function getGlobalFunction(name) {
|
|
151
143
|
validateString(name);
|
|
152
144
|
let f = globalReference?.[name];
|
|
153
|
-
if (typeof f ===
|
|
145
|
+
if (typeof f === "undefined") throw new Error(`the function ${name} is not defined`);
|
|
154
146
|
validateFunction(f);
|
|
155
147
|
return f;
|
|
156
148
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|