@schukai/monster 3.13.0 → 3.14.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/package.json +1 -1
- package/source/data/datasource/server/restapi.mjs +7 -0
- package/source/data/datasource.mjs +1 -0
- package/source/data/transformer.mjs +24 -3
- package/source/dom/updater.mjs +2 -2
- package/source/types/version.mjs +1 -1
- package/test/cases/data/transformer.mjs +7 -6
- package/test/cases/monster.mjs +1 -1
package/package.json
CHANGED
|
@@ -169,6 +169,13 @@ class RestAPI extends Server {
|
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
/**
|
|
173
|
+
* @private
|
|
174
|
+
* @param init
|
|
175
|
+
* @param key
|
|
176
|
+
* @param callback
|
|
177
|
+
* @returns {Promise<string>}
|
|
178
|
+
*/
|
|
172
179
|
function fetchData(init, key, callback) {
|
|
173
180
|
const self = this;
|
|
174
181
|
let response;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import {Base} from "../types/base.mjs";
|
|
9
9
|
import {getGlobal, getGlobalObject} from "../types/global.mjs";
|
|
10
10
|
import {ID} from "../types/id.mjs";
|
|
11
|
-
import {isArray, isObject, isString} from "../types/is.mjs";
|
|
11
|
+
import {isArray, isObject, isString, isPrimitive} from "../types/is.mjs";
|
|
12
12
|
import {getDocumentTranslations, Translations} from "../i18n/translations.mjs";
|
|
13
13
|
import {
|
|
14
14
|
validateFunction,
|
|
@@ -397,6 +397,28 @@ function transform(value) {
|
|
|
397
397
|
|
|
398
398
|
return new Pathfinder(value).exists(key);
|
|
399
399
|
|
|
400
|
+
case "concat":
|
|
401
|
+
let pf2 = new Pathfinder(value);
|
|
402
|
+
let concat = "";
|
|
403
|
+
while (args.length > 0) {
|
|
404
|
+
key = args.shift();
|
|
405
|
+
if (key === undefined) {
|
|
406
|
+
throw new Error("missing key parameter");
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (!pf2.exists(key)) {
|
|
410
|
+
concat += key;
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
let v = pf2.getVia(key);
|
|
414
|
+
if(!isPrimitive(v)) {
|
|
415
|
+
throw new Error("value is not primitive");
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
concat += v;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
return concat;
|
|
400
422
|
case "path":
|
|
401
423
|
key = args.shift();
|
|
402
424
|
if (key === undefined) {
|
|
@@ -465,7 +487,6 @@ function transform(value) {
|
|
|
465
487
|
|
|
466
488
|
case "i18n":
|
|
467
489
|
case "translation":
|
|
468
|
-
|
|
469
490
|
translations = getDocumentTranslations();
|
|
470
491
|
if (!(translations instanceof Translations)) {
|
|
471
492
|
throw new Error("missing translations");
|
|
@@ -475,7 +496,7 @@ function transform(value) {
|
|
|
475
496
|
if (key === undefined) {
|
|
476
497
|
key = value;
|
|
477
498
|
}
|
|
478
|
-
|
|
499
|
+
|
|
479
500
|
defaultValue = args.shift() || undefined;
|
|
480
501
|
return translations.getText(key, defaultValue);
|
|
481
502
|
|
package/source/dom/updater.mjs
CHANGED
|
@@ -614,7 +614,7 @@ function runUpdateContent(container, parts, subject) {
|
|
|
614
614
|
parts.pop();
|
|
615
615
|
|
|
616
616
|
// Unfortunately, static data is always changed as well, since it is not possible to react to changes here.
|
|
617
|
-
const query = `[${ATTRIBUTE_UPDATER_REPLACE}^="path:${current}"], [${ATTRIBUTE_UPDATER_REPLACE}^="static:"]`;
|
|
617
|
+
const query = `[${ATTRIBUTE_UPDATER_REPLACE}^="path:${current}"], [${ATTRIBUTE_UPDATER_REPLACE}^="static:"], [${ATTRIBUTE_UPDATER_REPLACE}^="i18n:"]`;
|
|
618
618
|
const e = container.querySelectorAll(`${query}`);
|
|
619
619
|
|
|
620
620
|
const iterator = new Set([...e]);
|
|
@@ -702,7 +702,7 @@ function runUpdateAttributes(container, parts, subject) {
|
|
|
702
702
|
|
|
703
703
|
let iterator = new Set();
|
|
704
704
|
|
|
705
|
-
const query = `[${ATTRIBUTE_UPDATER_SELECT_THIS}], [${ATTRIBUTE_UPDATER_ATTRIBUTES}*="path:${current}"], [${ATTRIBUTE_UPDATER_ATTRIBUTES}^="static:"]`;
|
|
705
|
+
const query = `[${ATTRIBUTE_UPDATER_SELECT_THIS}], [${ATTRIBUTE_UPDATER_ATTRIBUTES}*="path:${current}"], [${ATTRIBUTE_UPDATER_ATTRIBUTES}^="static:"], [${ATTRIBUTE_UPDATER_ATTRIBUTES}^="i18n:"]`;
|
|
706
706
|
|
|
707
707
|
const e = container.querySelectorAll(query);
|
|
708
708
|
|
package/source/types/version.mjs
CHANGED
|
@@ -27,6 +27,7 @@ describe('Transformer', function () {
|
|
|
27
27
|
describe('Transformer.run()', function () {
|
|
28
28
|
|
|
29
29
|
[
|
|
30
|
+
['concat:a.b.c:test:a.b.d', {a: {b: {c: 4, d: 6}}}, "4test6"],
|
|
30
31
|
['??:a', null, 'a'],
|
|
31
32
|
['??:a', undefined, 'a'],
|
|
32
33
|
['??:a', 'true', 'true'],
|
|
@@ -237,11 +238,11 @@ describe('Transformer', function () {
|
|
|
237
238
|
});
|
|
238
239
|
|
|
239
240
|
[
|
|
240
|
-
[
|
|
241
|
-
[
|
|
242
|
-
[
|
|
243
|
-
[
|
|
244
|
-
[
|
|
241
|
+
['i18n:test1', "", "xyz"],
|
|
242
|
+
['i18n:', "test1", "xyz"], // key by value
|
|
243
|
+
['i18n::', "test1", "xyz"], // key by value no default
|
|
244
|
+
['i18n::eee', "test2", "eee"], // key by value with default
|
|
245
|
+
['i18n::ddd', "test2", "ddd"], // key by value and default
|
|
245
246
|
|
|
246
247
|
].forEach(function (data) {
|
|
247
248
|
|
|
@@ -249,7 +250,7 @@ describe('Transformer', function () {
|
|
|
249
250
|
let b = data.shift()
|
|
250
251
|
let c = data.shift()
|
|
251
252
|
|
|
252
|
-
it('should transform('+a+').run('+b+') return ' + JSON.stringify(c), function () {
|
|
253
|
+
it('should transform(' + a + ').run(' + b + ') return ' + JSON.stringify(c), function () {
|
|
253
254
|
const t = new Transformer(a);
|
|
254
255
|
expect(t.run(b)).to.be.eql(c);
|
|
255
256
|
});
|
package/test/cases/monster.mjs
CHANGED