@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
package/source/types/id.mjs
CHANGED
@@ -5,16 +5,16 @@
|
|
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 "./validate.mjs";
|
8
|
+
import { Base } from "./base.mjs";
|
9
|
+
import { validateString } from "./validate.mjs";
|
10
10
|
|
11
|
-
export {ID}
|
11
|
+
export { ID };
|
12
12
|
|
13
13
|
/**
|
14
14
|
* @private
|
15
15
|
* @type {Map<string, integer>}
|
16
16
|
*/
|
17
|
-
let internalCounter = new Map;
|
17
|
+
let internalCounter = new Map();
|
18
18
|
|
19
19
|
/**
|
20
20
|
* With the id class, sequences of ids can be created. for this purpose, an internal counter is incremented for each prefix.
|
@@ -32,7 +32,6 @@ let internalCounter = new Map;
|
|
32
32
|
* @summary Automatic generation of ids
|
33
33
|
*/
|
34
34
|
class ID extends Base {
|
35
|
-
|
36
35
|
/**
|
37
36
|
* create new id with prefix
|
38
37
|
*
|
@@ -63,5 +62,4 @@ class ID extends Base {
|
|
63
62
|
toString() {
|
64
63
|
return this.id;
|
65
64
|
}
|
66
|
-
|
67
65
|
}
|
package/source/types/is.mjs
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
export {isIterable, isPrimitive, isSymbol, isBoolean, isString, isObject, isInstance, isArray, isFunction, isInteger}
|
8
|
+
export { isIterable, isPrimitive, isSymbol, isBoolean, isString, isObject, isInstance, isArray, isFunction, isInteger };
|
9
9
|
|
10
10
|
/**
|
11
11
|
* With this function you can check if a value is iterable.
|
@@ -25,10 +25,9 @@ export {isIterable, isPrimitive, isSymbol, isBoolean, isString, isObject, isInst
|
|
25
25
|
function isIterable(value) {
|
26
26
|
if (value === undefined) return false;
|
27
27
|
if (value === null) return false;
|
28
|
-
return typeof value?.[Symbol.iterator] ===
|
28
|
+
return typeof value?.[Symbol.iterator] === "function";
|
29
29
|
}
|
30
30
|
|
31
|
-
|
32
31
|
/**
|
33
32
|
* Checks whether the value passed is a primitive (string, number, boolean, NaN, undefined, null or symbol)
|
34
33
|
*
|
@@ -51,7 +50,7 @@ function isPrimitive(value) {
|
|
51
50
|
|
52
51
|
type = typeof value;
|
53
52
|
|
54
|
-
if (type ===
|
53
|
+
if (type === "string" || type === "number" || type === "boolean" || type === "symbol") {
|
55
54
|
return true;
|
56
55
|
}
|
57
56
|
|
@@ -72,7 +71,7 @@ function isPrimitive(value) {
|
|
72
71
|
* @memberOf Monster.Types
|
73
72
|
*/
|
74
73
|
function isSymbol(value) {
|
75
|
-
return
|
74
|
+
return "symbol" === typeof value ? true : false;
|
76
75
|
}
|
77
76
|
|
78
77
|
/**
|
@@ -89,7 +88,6 @@ function isSymbol(value) {
|
|
89
88
|
* @memberOf Monster.Types
|
90
89
|
*/
|
91
90
|
function isBoolean(value) {
|
92
|
-
|
93
91
|
if (value === true || value === false) {
|
94
92
|
return true;
|
95
93
|
}
|
@@ -111,7 +109,7 @@ function isBoolean(value) {
|
|
111
109
|
* @memberOf Monster.Types
|
112
110
|
*/
|
113
111
|
function isString(value) {
|
114
|
-
if (value === undefined || typeof value !==
|
112
|
+
if (value === undefined || typeof value !== "string") {
|
115
113
|
return false;
|
116
114
|
}
|
117
115
|
return true;
|
@@ -131,11 +129,10 @@ function isString(value) {
|
|
131
129
|
* @memberOf Monster.Types
|
132
130
|
*/
|
133
131
|
function isObject(value) {
|
134
|
-
|
135
132
|
if (isArray(value)) return false;
|
136
133
|
if (isPrimitive(value)) return false;
|
137
134
|
|
138
|
-
if (typeof value ===
|
135
|
+
if (typeof value === "object") {
|
139
136
|
return true;
|
140
137
|
}
|
141
138
|
|
@@ -146,7 +143,7 @@ function isObject(value) {
|
|
146
143
|
* Checks whether the value passed is a object and instance of instance.
|
147
144
|
*
|
148
145
|
* This method is used in the library to have consistent names.
|
149
|
-
*
|
146
|
+
*
|
150
147
|
* @externalExample ../../example/types/is-7.mjs
|
151
148
|
* @param {*} value
|
152
149
|
* @param {*} instance
|
@@ -159,8 +156,8 @@ function isObject(value) {
|
|
159
156
|
function isInstance(value, instance) {
|
160
157
|
if (!isObject(value)) return false;
|
161
158
|
if (!isFunction(instance)) return false;
|
162
|
-
if (!instance.hasOwnProperty(
|
163
|
-
return
|
159
|
+
if (!instance.hasOwnProperty("prototype")) return false;
|
160
|
+
return value instanceof instance ? true : false;
|
164
161
|
}
|
165
162
|
|
166
163
|
/**
|
@@ -185,7 +182,7 @@ function isArray(value) {
|
|
185
182
|
* Checks whether the value passed is a function
|
186
183
|
*
|
187
184
|
* This method is used in the library to have consistent names.
|
188
|
-
*
|
185
|
+
*
|
189
186
|
* @externalExample ../../example/types/is-9.mjs
|
190
187
|
* @param {*} value
|
191
188
|
* @returns {boolean}
|
@@ -198,12 +195,11 @@ function isFunction(value) {
|
|
198
195
|
if (isArray(value)) return false;
|
199
196
|
if (isPrimitive(value)) return false;
|
200
197
|
|
201
|
-
if (typeof value ===
|
198
|
+
if (typeof value === "function") {
|
202
199
|
return true;
|
203
200
|
}
|
204
201
|
|
205
202
|
return false;
|
206
|
-
|
207
203
|
}
|
208
204
|
|
209
205
|
/**
|
@@ -222,4 +218,3 @@ function isFunction(value) {
|
|
222
218
|
function isInteger(value) {
|
223
219
|
return Number.isInteger(value);
|
224
220
|
}
|
225
|
-
|
@@ -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 "./base.mjs";
|
9
|
-
import {isString} from "./is.mjs";
|
10
|
-
import {validateArray, validateString} from "./validate.mjs";
|
11
|
-
import {instanceSymbol} from
|
12
|
-
export {MediaType, parseMediaType}
|
8
|
+
import { Base } from "./base.mjs";
|
9
|
+
import { isString } from "./is.mjs";
|
10
|
+
import { validateArray, validateString } from "./validate.mjs";
|
11
|
+
import { instanceSymbol } from "../constants.mjs";
|
12
|
+
export { MediaType, parseMediaType };
|
13
13
|
|
14
14
|
/**
|
15
15
|
* @private
|
16
16
|
* @type {symbol}
|
17
17
|
*/
|
18
|
-
const internal = Symbol(
|
18
|
+
const internal = Symbol("internal");
|
19
19
|
|
20
20
|
/**
|
21
21
|
* @typedef {Object} Parameter
|
@@ -24,7 +24,6 @@ const internal = Symbol('internal');
|
|
24
24
|
* @memberOf Monster.Types
|
25
25
|
*/
|
26
26
|
|
27
|
-
|
28
27
|
/**
|
29
28
|
* You can create an object via the monster namespace `new Monster.Types.MediaType()`.
|
30
29
|
*
|
@@ -34,7 +33,6 @@ const internal = Symbol('internal');
|
|
34
33
|
* @memberOf Monster.Types
|
35
34
|
*/
|
36
35
|
class MediaType extends Base {
|
37
|
-
|
38
36
|
/**
|
39
37
|
*
|
40
38
|
* @param {String} type
|
@@ -47,14 +45,12 @@ class MediaType extends Base {
|
|
47
45
|
this[internal] = {
|
48
46
|
type: validateString(type).toLowerCase(),
|
49
47
|
subtype: validateString(subtype).toLowerCase(),
|
50
|
-
parameter: []
|
51
|
-
}
|
48
|
+
parameter: [],
|
49
|
+
};
|
52
50
|
|
53
51
|
if (parameter !== undefined) {
|
54
|
-
this[internal][
|
52
|
+
this[internal]["parameter"] = validateArray(parameter);
|
55
53
|
}
|
56
|
-
|
57
|
-
|
58
54
|
}
|
59
55
|
|
60
56
|
/**
|
@@ -66,7 +62,6 @@ class MediaType extends Base {
|
|
66
62
|
return Symbol.for("@schukai/monster/types/media-type");
|
67
63
|
}
|
68
64
|
|
69
|
-
|
70
65
|
/**
|
71
66
|
* @return {String}
|
72
67
|
*/
|
@@ -94,11 +89,9 @@ class MediaType extends Base {
|
|
94
89
|
* @return {Map}
|
95
90
|
*/
|
96
91
|
get parameter() {
|
92
|
+
const result = new Map();
|
97
93
|
|
98
|
-
|
99
|
-
|
100
|
-
this[internal]['parameter'].forEach(p => {
|
101
|
-
|
94
|
+
this[internal]["parameter"].forEach((p) => {
|
102
95
|
let value = p.value;
|
103
96
|
|
104
97
|
// internally special values are partly stored with quotes, this function removes them.
|
@@ -107,8 +100,7 @@ class MediaType extends Base {
|
|
107
100
|
}
|
108
101
|
|
109
102
|
result.set(p.key, value);
|
110
|
-
})
|
111
|
-
|
103
|
+
});
|
112
104
|
|
113
105
|
return result;
|
114
106
|
}
|
@@ -118,15 +110,15 @@ class MediaType extends Base {
|
|
118
110
|
* @return {string}
|
119
111
|
*/
|
120
112
|
toString() {
|
121
|
-
|
122
113
|
let parameter = [];
|
123
114
|
for (let a of this[internal].parameter) {
|
124
|
-
parameter.push(a.key
|
115
|
+
parameter.push(`${a.key}=${a.value}`);
|
125
116
|
}
|
126
117
|
|
127
|
-
return this[internal].type
|
118
|
+
return `${this[internal].type}/${this[internal].subtype}${
|
119
|
+
parameter.length > 0 ? `;${parameter.join(";")}` : ""
|
120
|
+
}`;
|
128
121
|
}
|
129
|
-
|
130
122
|
}
|
131
123
|
|
132
124
|
/**
|
@@ -166,26 +158,24 @@ class MediaType extends Base {
|
|
166
158
|
* @memberOf Monster.Types
|
167
159
|
*/
|
168
160
|
function parseMediaType(mediatype) {
|
169
|
-
|
170
|
-
|
161
|
+
const regex =
|
162
|
+
/(?<type>[A-Za-z]+|\*)\/(?<subtype>([a-zA-Z0-9.\+_\-]+)|\*|)(?<parameter>\s*;\s*([a-zA-Z0-9]+)\s*(=\s*("?[A-Za-z0-9_\-]+"?))?)*/g;
|
171
163
|
const result = regex.exec(validateString(mediatype));
|
172
164
|
|
173
|
-
const groups = result?.[
|
165
|
+
const groups = result?.["groups"];
|
174
166
|
if (groups === undefined) {
|
175
|
-
throw new TypeError(
|
167
|
+
throw new TypeError("the mimetype can not be parsed");
|
176
168
|
}
|
177
169
|
|
178
|
-
const type = groups?.[
|
179
|
-
const subtype = groups?.[
|
180
|
-
const parameter = groups?.[
|
170
|
+
const type = groups?.["type"];
|
171
|
+
const subtype = groups?.["subtype"];
|
172
|
+
const parameter = groups?.["parameter"];
|
181
173
|
|
182
174
|
if (subtype === "" || type === "") {
|
183
|
-
throw new TypeError(
|
175
|
+
throw new TypeError("blank value is not allowed");
|
184
176
|
}
|
185
177
|
|
186
178
|
return new MediaType(type, subtype, parseParameter(parameter));
|
187
|
-
|
188
|
-
|
189
179
|
}
|
190
180
|
|
191
181
|
/**
|
@@ -197,21 +187,19 @@ function parseMediaType(mediatype) {
|
|
197
187
|
* @memberOf Monster.Types
|
198
188
|
*/
|
199
189
|
function parseParameter(parameter) {
|
200
|
-
|
201
190
|
if (!isString(parameter)) {
|
202
191
|
return undefined;
|
203
192
|
}
|
204
193
|
|
205
194
|
let result = [];
|
206
195
|
|
207
|
-
parameter.split(
|
208
|
-
|
196
|
+
parameter.split(";").forEach((entry) => {
|
209
197
|
entry = entry.trim();
|
210
198
|
if (entry === "") {
|
211
199
|
return;
|
212
200
|
}
|
213
201
|
|
214
|
-
const kv = entry.split(
|
202
|
+
const kv = entry.split("=");
|
215
203
|
|
216
204
|
let key = validateString(kv?.[0]).trim();
|
217
205
|
let value = validateString(kv?.[1]).trim();
|
@@ -219,12 +207,9 @@ function parseParameter(parameter) {
|
|
219
207
|
// if values are quoted, they remain so internally
|
220
208
|
result.push({
|
221
209
|
key: key,
|
222
|
-
value: value
|
223
|
-
})
|
224
|
-
|
225
|
-
|
226
|
-
})
|
210
|
+
value: value,
|
211
|
+
});
|
212
|
+
});
|
227
213
|
|
228
214
|
return result;
|
229
|
-
|
230
215
|
}
|
package/source/types/node.mjs
CHANGED
@@ -5,26 +5,25 @@
|
|
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 {isPrimitive} from "./is.mjs";
|
10
|
-
import {NodeList} from
|
11
|
-
import {validateInstance} from
|
12
|
-
import {instanceSymbol} from
|
8
|
+
import { Base } from "./base.mjs";
|
9
|
+
import { isPrimitive } from "./is.mjs";
|
10
|
+
import { NodeList } from "./nodelist.mjs";
|
11
|
+
import { validateInstance } from "./validate.mjs";
|
12
|
+
import { instanceSymbol } from "../constants.mjs";
|
13
13
|
|
14
|
-
export {Node}
|
14
|
+
export { Node };
|
15
15
|
|
16
16
|
/**
|
17
17
|
* @private
|
18
18
|
* @type {symbol}
|
19
19
|
*/
|
20
|
-
const internalValueSymbol = Symbol(
|
20
|
+
const internalValueSymbol = Symbol("internalData");
|
21
21
|
|
22
22
|
/**
|
23
23
|
* @private
|
24
24
|
* @type {symbol}
|
25
25
|
*/
|
26
|
-
const treeStructureSymbol = Symbol(
|
27
|
-
|
26
|
+
const treeStructureSymbol = Symbol("treeStructure");
|
28
27
|
|
29
28
|
/**
|
30
29
|
* You can create the instance via the monster namespace `new Monster.Types.Node()`.
|
@@ -37,7 +36,6 @@ const treeStructureSymbol = Symbol('treeStructure');
|
|
37
36
|
* @see https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Iteration_protocols
|
38
37
|
*/
|
39
38
|
class Node extends Base {
|
40
|
-
|
41
39
|
/**
|
42
40
|
* @param {*} [value]
|
43
41
|
*/
|
@@ -47,10 +45,9 @@ class Node extends Base {
|
|
47
45
|
|
48
46
|
this[treeStructureSymbol] = {
|
49
47
|
parent: null,
|
50
|
-
childNodes: new NodeList,
|
51
|
-
level: 0
|
52
|
-
}
|
53
|
-
|
48
|
+
childNodes: new NodeList(),
|
49
|
+
level: 0,
|
50
|
+
};
|
54
51
|
}
|
55
52
|
|
56
53
|
/**
|
@@ -62,7 +59,6 @@ class Node extends Base {
|
|
62
59
|
return Symbol.for("@schukai/monster/types/node");
|
63
60
|
}
|
64
61
|
|
65
|
-
|
66
62
|
/**
|
67
63
|
* @property {*}
|
68
64
|
*/
|
@@ -155,11 +151,10 @@ class Node extends Base {
|
|
155
151
|
* @return {string}
|
156
152
|
*/
|
157
153
|
toString() {
|
158
|
-
|
159
154
|
let parts = [];
|
160
155
|
if (this[internalValueSymbol]) {
|
161
156
|
let label = this[internalValueSymbol];
|
162
|
-
if (!isPrimitive(label)) label = JSON.stringify(this[internalValueSymbol])
|
157
|
+
if (!isPrimitive(label)) label = JSON.stringify(this[internalValueSymbol]);
|
163
158
|
|
164
159
|
parts.push(label);
|
165
160
|
}
|
@@ -168,18 +163,17 @@ class Node extends Base {
|
|
168
163
|
return parts.join("\n");
|
169
164
|
}
|
170
165
|
|
171
|
-
let count = this.childNodes.length
|
172
|
-
|
166
|
+
let count = this.childNodes.length;
|
167
|
+
let counter = 0;
|
173
168
|
|
174
169
|
for (const node of this.childNodes) {
|
175
170
|
counter++;
|
176
|
-
const prefix = (count === counter ?
|
171
|
+
const prefix = (count === counter ? "└" : "├").padStart(2 * node.level, " |");
|
177
172
|
parts.push(prefix + node.toString());
|
178
173
|
}
|
179
174
|
|
180
175
|
return parts.join("\n");
|
181
176
|
}
|
182
|
-
|
183
177
|
}
|
184
178
|
|
185
179
|
/**
|
@@ -192,7 +186,7 @@ function setChildLevelAndParent(node, operand) {
|
|
192
186
|
const self = this;
|
193
187
|
|
194
188
|
if (node !== this) {
|
195
|
-
node[treeStructureSymbol].parent = this
|
189
|
+
node[treeStructureSymbol].parent = this;
|
196
190
|
}
|
197
191
|
|
198
192
|
node[treeStructureSymbol].childNodes.forEach(function (child) {
|
@@ -5,11 +5,11 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {isArray, isInstance} from "./is.mjs";
|
9
|
-
import {Node} from "./node.mjs";
|
10
|
-
import {validateInstance} from "./validate.mjs";
|
11
|
-
import {instanceSymbol} from
|
12
|
-
export {NodeList}
|
8
|
+
import { isArray, isInstance } from "./is.mjs";
|
9
|
+
import { Node } from "./node.mjs";
|
10
|
+
import { validateInstance } from "./validate.mjs";
|
11
|
+
import { instanceSymbol } from "../constants.mjs";
|
12
|
+
export { NodeList };
|
13
13
|
|
14
14
|
/**
|
15
15
|
* You can create the instance via the monster namespace `new Monster.Types.NodeList()`.
|
@@ -21,7 +21,6 @@ export {NodeList}
|
|
21
21
|
* @summary A NodeList class
|
22
22
|
*/
|
23
23
|
class NodeList extends Set {
|
24
|
-
|
25
24
|
/**
|
26
25
|
* @throws {Error} invalid value type
|
27
26
|
* @param {NodeList|Node|Array<Node>}values
|
@@ -29,18 +28,18 @@ class NodeList extends Set {
|
|
29
28
|
constructor(values) {
|
30
29
|
super();
|
31
30
|
|
32
|
-
const self = this
|
31
|
+
const self = this;
|
33
32
|
|
34
33
|
if (values === undefined) return;
|
35
34
|
|
36
35
|
if (isArray(values)) {
|
37
|
-
values.forEach(value => self.add(value));
|
36
|
+
values.forEach((value) => self.add(value));
|
38
37
|
} else if (isInstance(values, NodeList)) {
|
39
|
-
values.forEach(value => self.add(value));
|
38
|
+
values.forEach((value) => self.add(value));
|
40
39
|
} else if (isInstance(values, Node)) {
|
41
40
|
self.add(values);
|
42
41
|
} else {
|
43
|
-
throw new Error(
|
42
|
+
throw new Error("invalid value type");
|
44
43
|
}
|
45
44
|
}
|
46
45
|
|
@@ -52,7 +51,6 @@ class NodeList extends Set {
|
|
52
51
|
static get [instanceSymbol]() {
|
53
52
|
return Symbol.for("@schukai/monster/types/node-list");
|
54
53
|
}
|
55
|
-
|
56
54
|
|
57
55
|
/**
|
58
56
|
*
|
@@ -79,7 +77,6 @@ class NodeList extends Set {
|
|
79
77
|
*/
|
80
78
|
has(node) {
|
81
79
|
return super.has(validateInstance(node, Node));
|
82
|
-
return false;
|
83
80
|
}
|
84
81
|
|
85
82
|
/**
|
@@ -111,7 +108,7 @@ class NodeList extends Set {
|
|
111
108
|
let parts = [];
|
112
109
|
|
113
110
|
for (const node of this.toArray()) {
|
114
|
-
parts.push(node.toString())
|
111
|
+
parts.push(node.toString());
|
115
112
|
}
|
116
113
|
|
117
114
|
return parts.join("\n");
|
@@ -121,4 +118,3 @@ class NodeList extends Set {
|
|
121
118
|
return super.size;
|
122
119
|
}
|
123
120
|
}
|
124
|
-
|
@@ -5,21 +5,21 @@
|
|
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";
|
8
|
+
import { internalSymbol } from "../constants.mjs";
|
9
9
|
|
10
|
-
import {Base} from
|
11
|
-
import {isInstance} from "./is.mjs";
|
12
|
-
import {Node} from "./node.mjs";
|
13
|
-
import {NodeList} from "./nodelist.mjs";
|
14
|
-
import {validateInstance} from "./validate.mjs";
|
10
|
+
import { Base } from "./base.mjs";
|
11
|
+
import { isInstance } from "./is.mjs";
|
12
|
+
import { Node } from "./node.mjs";
|
13
|
+
import { NodeList } from "./nodelist.mjs";
|
14
|
+
import { validateInstance } from "./validate.mjs";
|
15
15
|
|
16
|
-
export {NodeRecursiveIterator}
|
16
|
+
export { NodeRecursiveIterator };
|
17
17
|
|
18
18
|
/**
|
19
19
|
* @private
|
20
20
|
* @type {symbol}
|
21
21
|
*/
|
22
|
-
const isNodeListSymbol = Symbol(
|
22
|
+
const isNodeListSymbol = Symbol("isNodeList");
|
23
23
|
|
24
24
|
/**
|
25
25
|
* You can create the instance via the monster namespace `new Monster.Types.NodeRecursiveIterator()`.
|
@@ -31,8 +31,7 @@ const isNodeListSymbol = Symbol('isNodeList');
|
|
31
31
|
* @memberOf Monster.Types
|
32
32
|
* @summary An iterator to run recursively through a tree of nodes
|
33
33
|
*/
|
34
|
-
|
35
|
-
|
34
|
+
class NodeRecursiveIterator extends Base {
|
36
35
|
/**
|
37
36
|
* @param {Node} [data]
|
38
37
|
*/
|
@@ -57,7 +56,6 @@ const isNodeListSymbol = Symbol('isNodeList');
|
|
57
56
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/yield
|
58
57
|
*/
|
59
58
|
[Symbol.iterator] = function* () {
|
60
|
-
|
61
59
|
/**
|
62
60
|
* The end of the generator function is reached. In this case, execution of the generator
|
63
61
|
* ends and an IteratorResult is returned to the caller in which the value is undefined and done is true.
|
@@ -66,7 +64,7 @@ const isNodeListSymbol = Symbol('isNodeList');
|
|
66
64
|
if (this[internalSymbol] === undefined) {
|
67
65
|
return;
|
68
66
|
}
|
69
|
-
|
67
|
+
|
70
68
|
// iterator is a nodelist and the main node is only a placeholder
|
71
69
|
if (this[isNodeListSymbol] !== true) {
|
72
70
|
yield this[internalSymbol];
|
@@ -81,7 +79,7 @@ const isNodeListSymbol = Symbol('isNodeList');
|
|
81
79
|
}
|
82
80
|
|
83
81
|
return;
|
84
|
-
}
|
82
|
+
};
|
85
83
|
|
86
84
|
/**
|
87
85
|
* @param {function} callback
|
@@ -93,5 +91,4 @@ const isNodeListSymbol = Symbol('isNodeList');
|
|
93
91
|
}
|
94
92
|
return this;
|
95
93
|
}
|
96
|
-
|
97
94
|
}
|
@@ -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 {Queue} from
|
9
|
-
import {instanceSymbol, internalSymbol} from
|
10
|
-
import {ObserverList} from "./observerlist.mjs";
|
8
|
+
import { Queue } from "./queue.mjs";
|
9
|
+
import { instanceSymbol, internalSymbol } from "../constants.mjs";
|
10
|
+
import { ObserverList } from "./observerlist.mjs";
|
11
11
|
|
12
|
-
export {ObservableQueue};
|
12
|
+
export { ObservableQueue };
|
13
13
|
|
14
14
|
/**
|
15
15
|
* An observable queue is a list of items that are processed one after another (first in, first out).
|
16
|
-
*
|
16
|
+
*
|
17
17
|
* `Queue.add()` and `Queue.clear()` notify all observers.
|
18
|
-
*
|
18
|
+
*
|
19
19
|
* @externalExample ../../example/types/queue.mjs
|
20
20
|
* @license AGPLv3
|
21
21
|
* @since 3.3.0
|
@@ -24,14 +24,13 @@ export {ObservableQueue};
|
|
24
24
|
* @summary An observable Queue (Fifo)
|
25
25
|
*/
|
26
26
|
class ObservableQueue extends Queue {
|
27
|
-
|
28
27
|
/**
|
29
28
|
*
|
30
29
|
*/
|
31
30
|
constructor() {
|
32
31
|
super();
|
33
|
-
this[internalSymbol]= {
|
34
|
-
observers: new ObserverList()
|
32
|
+
this[internalSymbol] = {
|
33
|
+
observers: new ObserverList(),
|
35
34
|
};
|
36
35
|
}
|
37
36
|
|
@@ -43,7 +42,7 @@ class ObservableQueue extends Queue {
|
|
43
42
|
static get [instanceSymbol]() {
|
44
43
|
return Symbol.for("@schukai/monster/types/observablequeue");
|
45
44
|
}
|
46
|
-
|
45
|
+
|
47
46
|
/**
|
48
47
|
* Add a new element to the end of the queue.
|
49
48
|
*
|
@@ -74,7 +73,7 @@ class ObservableQueue extends Queue {
|
|
74
73
|
* @returns {ProxyObserver}
|
75
74
|
*/
|
76
75
|
attachObserver(observer) {
|
77
|
-
this[internalSymbol].observers.attach(observer)
|
76
|
+
this[internalSymbol].observers.attach(observer);
|
78
77
|
return this;
|
79
78
|
}
|
80
79
|
|
@@ -85,7 +84,7 @@ class ObservableQueue extends Queue {
|
|
85
84
|
* @returns {ProxyObserver}
|
86
85
|
*/
|
87
86
|
detachObserver(observer) {
|
88
|
-
this[internalSymbol].observers.detach(observer)
|
87
|
+
this[internalSymbol].observers.detach(observer);
|
89
88
|
return this;
|
90
89
|
}
|
91
90
|
|
@@ -103,8 +102,6 @@ class ObservableQueue extends Queue {
|
|
103
102
|
* @returns {boolean}
|
104
103
|
*/
|
105
104
|
containsObserver(observer) {
|
106
|
-
return this[internalSymbol].observers.contains(observer)
|
107
|
-
}
|
108
|
-
|
109
|
-
|
105
|
+
return this[internalSymbol].observers.contains(observer);
|
106
|
+
}
|
110
107
|
}
|