@schukai/monster 3.7.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/data/pathfinder.mjs +77 -32
- package/source/dom/focusmanager.mjs +1 -1
- package/source/dom/locale.mjs +2 -1
- package/source/i18n/locale.mjs +2 -13
- package/source/i18n/translations.mjs +2 -2
- package/source/types/version.mjs +1 -1
- package/test/cases/monster.mjs +1 -1
package/package.json
CHANGED
@@ -6,9 +6,9 @@
|
|
6
6
|
*/
|
7
7
|
|
8
8
|
import { Base } from "../types/base.mjs";
|
9
|
-
import { isArray, isInteger, isObject, isPrimitive } from "../types/is.mjs";
|
9
|
+
import { isArray, isInteger, isObject, isPrimitive, isString } from "../types/is.mjs";
|
10
10
|
import { Stack } from "../types/stack.mjs";
|
11
|
-
import { validateInteger, validateString } from "../types/validate.mjs";
|
11
|
+
import { validateInteger, validateBoolean, validateString } from "../types/validate.mjs";
|
12
12
|
|
13
13
|
export { Pathfinder, DELIMITER, WILDCARD };
|
14
14
|
|
@@ -103,7 +103,7 @@ class Pathfinder extends Base {
|
|
103
103
|
|
104
104
|
/**
|
105
105
|
*
|
106
|
-
* @param {string} path
|
106
|
+
* @param {string|array} path
|
107
107
|
* @since 1.4.0
|
108
108
|
* @returns {*}
|
109
109
|
* @throws {TypeError} unsupported type
|
@@ -113,12 +113,12 @@ class Pathfinder extends Base {
|
|
113
113
|
* @throws {Error} unsupported action for this data type
|
114
114
|
*/
|
115
115
|
getVia(path) {
|
116
|
-
return getValueViaPath.call(this, this.object,
|
116
|
+
return getValueViaPath.call(this, this.object, path);
|
117
117
|
}
|
118
118
|
|
119
119
|
/**
|
120
120
|
*
|
121
|
-
* @param {string} path
|
121
|
+
* @param {string|array} path
|
122
122
|
* @param {*} value
|
123
123
|
* @returns {Pathfinder}
|
124
124
|
* @since 1.4.0
|
@@ -128,7 +128,6 @@ class Pathfinder extends Base {
|
|
128
128
|
* @throws {Error} unsupported action for this data type
|
129
129
|
*/
|
130
130
|
setVia(path, value) {
|
131
|
-
validateString(path);
|
132
131
|
setValueViaPath.call(this, this.object, path, value);
|
133
132
|
return this;
|
134
133
|
}
|
@@ -136,7 +135,7 @@ class Pathfinder extends Base {
|
|
136
135
|
/**
|
137
136
|
* Delete Via Path
|
138
137
|
*
|
139
|
-
* @param {string} path
|
138
|
+
* @param {string|array} path
|
140
139
|
* @returns {Pathfinder}
|
141
140
|
* @since 1.6.0
|
142
141
|
* @throws {TypeError} unsupported type
|
@@ -145,14 +144,13 @@ class Pathfinder extends Base {
|
|
145
144
|
* @throws {Error} unsupported action for this data type
|
146
145
|
*/
|
147
146
|
deleteVia(path) {
|
148
|
-
validateString(path);
|
149
147
|
deleteValueViaPath.call(this, this.object, path);
|
150
148
|
return this;
|
151
149
|
}
|
152
150
|
|
153
151
|
/**
|
154
152
|
*
|
155
|
-
* @param {string} path
|
153
|
+
* @param {string|array} path
|
156
154
|
* @return {bool}
|
157
155
|
* @throws {TypeError} unsupported type
|
158
156
|
* @throws {TypeError} value is not a string
|
@@ -160,7 +158,6 @@ class Pathfinder extends Base {
|
|
160
158
|
* @since 1.4.0
|
161
159
|
*/
|
162
160
|
exists(path) {
|
163
|
-
validateString(path);
|
164
161
|
try {
|
165
162
|
getValueViaPath.call(this, this.object, path, true);
|
166
163
|
return true;
|
@@ -173,8 +170,8 @@ class Pathfinder extends Base {
|
|
173
170
|
/**
|
174
171
|
*
|
175
172
|
* @param {*} subject
|
176
|
-
* @param {string} path
|
177
|
-
* @param {
|
173
|
+
* @param {string|array} path
|
174
|
+
* @param {boolean} check
|
178
175
|
* @return {Map}
|
179
176
|
* @throws {TypeError} unsupported type
|
180
177
|
* @throws {Error} the journey is not at its end
|
@@ -182,8 +179,17 @@ class Pathfinder extends Base {
|
|
182
179
|
* @private
|
183
180
|
*/
|
184
181
|
function iterate(subject, path, check) {
|
182
|
+
if (check === undefined) {
|
183
|
+
check = false;
|
184
|
+
}
|
185
|
+
validateBoolean(check);
|
186
|
+
|
185
187
|
const result = new Map();
|
186
188
|
|
189
|
+
if (isArray(path)) {
|
190
|
+
path = path.join(DELIMITER);
|
191
|
+
}
|
192
|
+
|
187
193
|
if (isObject(subject) || isArray(subject)) {
|
188
194
|
for (const [key, value] of Object.entries(subject)) {
|
189
195
|
result.set(key, getValueViaPath.call(this, value, path, check));
|
@@ -199,7 +205,7 @@ function iterate(subject, path, check) {
|
|
199
205
|
/**
|
200
206
|
*
|
201
207
|
* @param {*} subject
|
202
|
-
* @param [string} path
|
208
|
+
* @param [string|array} path
|
203
209
|
* @param [boolean} check
|
204
210
|
* @returns {*}
|
205
211
|
* @throws {TypeError} unsupported type
|
@@ -208,11 +214,24 @@ function iterate(subject, path, check) {
|
|
208
214
|
* @private
|
209
215
|
*/
|
210
216
|
function getValueViaPath(subject, path, check) {
|
211
|
-
if (
|
212
|
-
|
217
|
+
if (check === undefined) {
|
218
|
+
check = false;
|
219
|
+
}
|
220
|
+
validateBoolean(check);
|
221
|
+
|
222
|
+
if (!(isArray(path) || isString(path))) {
|
223
|
+
throw new Error("type error: path must be a string or an array");
|
224
|
+
}
|
225
|
+
|
226
|
+
let parts;
|
227
|
+
if (isString(path)) {
|
228
|
+
if (path === "") {
|
229
|
+
return subject;
|
230
|
+
}
|
231
|
+
|
232
|
+
parts = path.split(DELIMITER);
|
213
233
|
}
|
214
234
|
|
215
|
-
let parts = path.split(DELIMITER);
|
216
235
|
let current = parts.shift();
|
217
236
|
|
218
237
|
if (current === this.wildCard) {
|
@@ -261,9 +280,9 @@ function getValueViaPath(subject, path, check) {
|
|
261
280
|
|
262
281
|
/**
|
263
282
|
*
|
264
|
-
* @param object
|
265
|
-
* @param path
|
266
|
-
* @param value
|
283
|
+
* @param {object} subject
|
284
|
+
* @param {string|array} path
|
285
|
+
* @param {*} value
|
267
286
|
* @returns {void}
|
268
287
|
* @throws {TypeError} unsupported type
|
269
288
|
* @throws {TypeError} unsupported type
|
@@ -271,10 +290,22 @@ function getValueViaPath(subject, path, check) {
|
|
271
290
|
* @throws {Error} unsupported action for this data type
|
272
291
|
* @private
|
273
292
|
*/
|
274
|
-
function setValueViaPath(
|
275
|
-
|
293
|
+
function setValueViaPath(subject, path, value) {
|
294
|
+
if (!(isArray(path) || isString(path))) {
|
295
|
+
throw new Error("type error: path must be a string or an array");
|
296
|
+
}
|
297
|
+
|
298
|
+
let parts;
|
299
|
+
if (isArray(path)) {
|
300
|
+
if (path.length === 0) {
|
301
|
+
return subject;
|
302
|
+
}
|
303
|
+
|
304
|
+
parts = path;
|
305
|
+
} else {
|
306
|
+
parts = path.split(DELIMITER);
|
307
|
+
}
|
276
308
|
|
277
|
-
let parts = path.split(DELIMITER);
|
278
309
|
let last = parts.pop();
|
279
310
|
let subpath = parts.join(DELIMITER);
|
280
311
|
|
@@ -282,7 +313,7 @@ function setValueViaPath(object, path, value) {
|
|
282
313
|
let current = subpath;
|
283
314
|
while (true) {
|
284
315
|
try {
|
285
|
-
getValueViaPath.call(this,
|
316
|
+
getValueViaPath.call(this, subject, current, true);
|
286
317
|
break;
|
287
318
|
} catch (e) {}
|
288
319
|
|
@@ -304,13 +335,13 @@ function setValueViaPath(object, path, value) {
|
|
304
335
|
}
|
305
336
|
}
|
306
337
|
|
307
|
-
setValueViaPath.call(this,
|
338
|
+
setValueViaPath.call(this, subject, current, obj);
|
308
339
|
}
|
309
340
|
|
310
|
-
let anchor = getValueViaPath.call(this,
|
341
|
+
let anchor = getValueViaPath.call(this, subject, subpath);
|
311
342
|
|
312
|
-
if (!(isObject(
|
313
|
-
throw TypeError(`unsupported type: ${typeof
|
343
|
+
if (!(isObject(subject) || isArray(subject))) {
|
344
|
+
throw TypeError(`unsupported type: ${typeof subject}`);
|
314
345
|
}
|
315
346
|
|
316
347
|
if (anchor instanceof Map || anchor instanceof WeakMap) {
|
@@ -349,8 +380,8 @@ function assignProperty(object, key, value) {
|
|
349
380
|
|
350
381
|
/**
|
351
382
|
*
|
352
|
-
* @param object
|
353
|
-
* @param path
|
383
|
+
* @param {object} subject
|
384
|
+
* @param {string} path
|
354
385
|
* @returns {void}
|
355
386
|
* @throws {TypeError} unsupported type
|
356
387
|
* @throws {TypeError} unsupported type
|
@@ -360,12 +391,26 @@ function assignProperty(object, key, value) {
|
|
360
391
|
* @since 1.6.0
|
361
392
|
* @private
|
362
393
|
*/
|
363
|
-
function deleteValueViaPath(
|
364
|
-
|
394
|
+
function deleteValueViaPath(subject, path) {
|
395
|
+
if (!(isArray(path) || isString(path))) {
|
396
|
+
throw new Error("type error: path must be a string or an array");
|
397
|
+
}
|
398
|
+
|
399
|
+
let parts;
|
400
|
+
if (isArray(path)) {
|
401
|
+
if (path.length === 0) {
|
402
|
+
return subject;
|
403
|
+
}
|
404
|
+
|
405
|
+
parts = path;
|
406
|
+
} else {
|
407
|
+
parts = path.split(DELIMITER);
|
408
|
+
}
|
409
|
+
|
365
410
|
let last = parts.pop();
|
366
411
|
const subpath = parts.join(DELIMITER);
|
367
412
|
|
368
|
-
const anchor = getValueViaPath.call(this,
|
413
|
+
const anchor = getValueViaPath.call(this, subject, subpath);
|
369
414
|
|
370
415
|
if (anchor instanceof Map) {
|
371
416
|
anchor.delete(last);
|
@@ -33,7 +33,7 @@ const KEY_CONTEXT = "context";
|
|
33
33
|
const stackSymbol = Symbol("stack");
|
34
34
|
|
35
35
|
/**
|
36
|
-
* With the
|
36
|
+
* With the focus manager the focus can be stored in a document, recalled and moved.
|
37
37
|
*
|
38
38
|
* @license AGPLv3
|
39
39
|
* @since 1.25.0
|
package/source/dom/locale.mjs
CHANGED
@@ -20,12 +20,13 @@ const DEFAULT_LANGUAGE = "en";
|
|
20
20
|
/**
|
21
21
|
* With this function you can read the language version set by the document.
|
22
22
|
* For this the attribute `lang` in the html tag is read. If no attribute is set, `en` is used as default.
|
23
|
+
* Alternatively, the language version of the browser is used.
|
23
24
|
*
|
24
25
|
* ```html
|
25
26
|
* <html lang="en">
|
26
27
|
* ```
|
27
28
|
*
|
28
|
-
* You can call the function via
|
29
|
+
* You can call the function via `getLocaleOfDocument()`.
|
29
30
|
*
|
30
31
|
* @license AGPLv3
|
31
32
|
* @since 1.13.0
|
package/source/i18n/locale.mjs
CHANGED
@@ -182,22 +182,11 @@ class Locale extends Base {
|
|
182
182
|
*
|
183
183
|
* Limitations: The regex cannot handle multiple variants or private.
|
184
184
|
*
|
185
|
-
* You can call the method via
|
185
|
+
* You can call the method via this function individually:
|
186
186
|
*
|
187
|
-
* ```
|
188
|
-
* <script type="module">
|
189
|
-
* import {Monster} from '@schukai/monster/source/monster.mjs';
|
190
|
-
* new Monster.I18n.createLocale()
|
191
|
-
* </script>
|
192
|
-
* ```
|
193
|
-
*
|
194
|
-
* Alternatively, you can also integrate this function individually.
|
195
|
-
*
|
196
|
-
* ```
|
197
|
-
* <script type="module">
|
187
|
+
* ```javascript
|
198
188
|
* import {createLocale} from '@schukai/monster/source/i18n/locale.mjs';
|
199
189
|
* createLocale()
|
200
|
-
* </script>
|
201
190
|
* ```
|
202
191
|
*
|
203
192
|
* RFC
|
@@ -112,9 +112,9 @@ class Translations extends Base {
|
|
112
112
|
* Set a text for a key
|
113
113
|
*
|
114
114
|
* ```
|
115
|
-
* translations.setText("text1"
|
115
|
+
* translations.setText("text1", "Make my day!");
|
116
116
|
* // plural rules
|
117
|
-
* translations.setText("text6"
|
117
|
+
* translations.setText("text6", {
|
118
118
|
* "zero": "There are no files on Disk.",
|
119
119
|
* "one": "There is one file on Disk.",
|
120
120
|
* "other": "There are files on Disk."
|
package/source/types/version.mjs
CHANGED
package/test/cases/monster.mjs
CHANGED