@schukai/monster 3.13.1 → 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
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) {
|
|
@@ -474,7 +496,7 @@ function transform(value) {
|
|
|
474
496
|
if (key === undefined) {
|
|
475
497
|
key = value;
|
|
476
498
|
}
|
|
477
|
-
|
|
499
|
+
|
|
478
500
|
defaultValue = args.shift() || undefined;
|
|
479
501
|
return translations.getText(key, defaultValue);
|
|
480
502
|
|
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