@schukai/monster 3.13.0 → 3.14.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "3.13.0",
3
+ "version": "3.14.0",
4
4
  "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
5
5
  "keywords": [
6
6
  "framework",
@@ -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;
@@ -53,6 +53,7 @@ class Datasource extends Base {
53
53
  */
54
54
  constructor() {
55
55
  super();
56
+
56
57
  this[internalSymbol] = new ProxyObserver({
57
58
  options: extend({}, this.defaults),
58
59
  });
@@ -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
 
@@ -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
 
@@ -142,7 +142,7 @@ function getMonsterVersion() {
142
142
  }
143
143
 
144
144
  /** don't touch, replaced by make with package.json version */
145
- monsterVersion = new Version("3.13.0");
145
+ monsterVersion = new Version("3.14.0");
146
146
 
147
147
  return monsterVersion;
148
148
  }
@@ -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
- [ 'i18n:test1',"", "xyz"],
241
- [ 'i18n:',"test1", "xyz"], // key by value
242
- [ 'i18n::',"test1", "xyz"], // key by value no default
243
- [ 'i18n::eee',"test2", "eee"], // key by value with default
244
- [ 'i18n::ddd',"test2", "ddd"], // key by value and default
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
  });
@@ -7,7 +7,7 @@ describe('Monster', function () {
7
7
  let monsterVersion
8
8
 
9
9
  /** don´t touch, replaced by make with package.json version */
10
- monsterVersion = new Version("3.13.0")
10
+ monsterVersion = new Version("3.14.0")
11
11
 
12
12
  let m = getMonsterVersion();
13
13