@schukai/monster 1.15.5 → 1.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. package/CHANGELOG +25 -0
  2. package/README.md +4 -4
  3. package/dist/modules/constants.js +1 -1
  4. package/dist/modules/constraints/abstract.js +1 -1
  5. package/dist/modules/constraints/abstractoperator.js +1 -1
  6. package/dist/modules/constraints/andoperator.js +1 -1
  7. package/dist/modules/constraints/invalid.js +1 -1
  8. package/dist/modules/constraints/isarray.js +1 -1
  9. package/dist/modules/constraints/isobject.js +1 -1
  10. package/dist/modules/constraints/namespace.js +2 -2
  11. package/dist/modules/constraints/oroperator.js +1 -1
  12. package/dist/modules/constraints/valid.js +1 -1
  13. package/dist/modules/data/buildmap.js +2 -2
  14. package/dist/modules/data/diff.js +2 -2
  15. package/dist/modules/data/extend.js +1 -1
  16. package/dist/modules/data/namespace.js +2 -2
  17. package/dist/modules/data/pathfinder.js +2 -2
  18. package/dist/modules/data/pipe.js +1 -1
  19. package/dist/modules/data/transformer.js +1 -1
  20. package/dist/modules/dom/assembler.js +1 -1
  21. package/dist/modules/dom/attributes.js +1 -1
  22. package/dist/modules/dom/constants.js +1 -1
  23. package/dist/modules/dom/customcontrol.js +1 -1
  24. package/dist/modules/dom/customelement.js +1 -1
  25. package/dist/modules/dom/events.js +1 -1
  26. package/dist/modules/dom/locale.js +1 -1
  27. package/dist/modules/dom/namespace.js +2 -2
  28. package/dist/modules/dom/template.js +1 -1
  29. package/dist/modules/dom/theme.js +1 -1
  30. package/dist/modules/dom/updater.js +1 -1
  31. package/dist/modules/dom/util.js +1 -1
  32. package/dist/modules/i18n/locale.js +1 -1
  33. package/dist/modules/i18n/namespace.js +2 -2
  34. package/dist/modules/i18n/provider.js +1 -1
  35. package/dist/modules/i18n/providers/fetch.js +1 -1
  36. package/dist/modules/i18n/providers/namespace.js +2 -2
  37. package/dist/modules/i18n/translations.js +1 -1
  38. package/dist/modules/logging/handler/console.js +2 -2
  39. package/dist/modules/logging/handler/namespace.js +2 -2
  40. package/dist/modules/logging/handler.js +1 -1
  41. package/dist/modules/logging/logentry.js +1 -1
  42. package/dist/modules/logging/logger.js +1 -1
  43. package/dist/modules/logging/namespace.js +2 -2
  44. package/dist/modules/math/namespace.js +2 -2
  45. package/dist/modules/math/random.js +1 -1
  46. package/dist/modules/monster.js +1 -1
  47. package/dist/modules/namespace.js +1 -1
  48. package/dist/modules/text/formatter.js +1 -1
  49. package/dist/modules/text/namespace.js +2 -2
  50. package/dist/modules/types/base.js +1 -1
  51. package/dist/modules/types/basewithoptions.js +1 -1
  52. package/dist/modules/types/global.js +1 -1
  53. package/dist/modules/types/id.js +1 -1
  54. package/dist/modules/types/is.js +1 -1
  55. package/dist/modules/types/namespace.js +2 -2
  56. package/dist/modules/types/observer.js +1 -1
  57. package/dist/modules/types/observerlist.js +1 -1
  58. package/dist/modules/types/proxyobserver.js +1 -1
  59. package/dist/modules/types/queue.js +1 -1
  60. package/dist/modules/types/randomid.js +1 -1
  61. package/dist/modules/types/stack.js +1 -1
  62. package/dist/modules/types/tokenlist.js +1 -1
  63. package/dist/modules/types/typeof.js +1 -1
  64. package/dist/modules/types/uniquequeue.js +1 -1
  65. package/dist/modules/types/validate.js +1 -1
  66. package/dist/modules/types/version.js +2 -2
  67. package/dist/modules/util/clone.js +1 -1
  68. package/dist/modules/util/comparator.js +1 -1
  69. package/dist/modules/util/freeze.js +1 -1
  70. package/dist/modules/util/namespace.js +2 -2
  71. package/dist/monster.dev.js +1293 -943
  72. package/dist/monster.dev.js.map +1 -1
  73. package/dist/monster.js +2 -2
  74. package/package.json +1 -1
  75. package/source/constraints/abstract.js +1 -1
  76. package/source/constraints/abstractoperator.js +1 -1
  77. package/source/constraints/andoperator.js +6 -6
  78. package/source/constraints/invalid.js +4 -4
  79. package/source/constraints/isarray.js +4 -4
  80. package/source/constraints/isobject.js +4 -4
  81. package/source/constraints/namespace.js +3 -2
  82. package/source/constraints/oroperator.js +6 -6
  83. package/source/constraints/valid.js +4 -4
  84. package/source/data/buildmap.js +245 -12
  85. package/source/data/diff.js +7 -6
  86. package/source/data/extend.js +3 -3
  87. package/source/data/namespace.js +3 -2
  88. package/source/data/pathfinder.js +15 -11
  89. package/source/data/pipe.js +4 -4
  90. package/source/data/transformer.js +4 -4
  91. package/source/dom/assembler.js +4 -4
  92. package/source/dom/attributes.js +36 -46
  93. package/source/dom/constants.js +16 -14
  94. package/source/dom/customcontrol.js +12 -8
  95. package/source/dom/customelement.js +24 -11
  96. package/source/dom/events.js +6 -6
  97. package/source/dom/locale.js +5 -4
  98. package/source/dom/namespace.js +3 -2
  99. package/source/dom/template.js +6 -6
  100. package/source/dom/theme.js +5 -4
  101. package/source/dom/updater.js +11 -5
  102. package/source/dom/util.js +9 -9
  103. package/source/i18n/locale.js +27 -15
  104. package/source/i18n/namespace.js +3 -2
  105. package/source/i18n/provider.js +3 -3
  106. package/source/i18n/providers/fetch.js +22 -6
  107. package/source/i18n/providers/namespace.js +3 -2
  108. package/source/i18n/translations.js +3 -3
  109. package/source/logging/handler/console.js +34 -10
  110. package/source/logging/handler/namespace.js +3 -2
  111. package/source/logging/handler.js +4 -4
  112. package/source/logging/logentry.js +5 -5
  113. package/source/logging/logger.js +13 -13
  114. package/source/logging/namespace.js +3 -2
  115. package/source/math/namespace.js +3 -2
  116. package/source/math/random.js +3 -3
  117. package/source/namespace.js +1 -1
  118. package/source/text/formatter.js +3 -3
  119. package/source/text/namespace.js +3 -2
  120. package/source/types/base.js +3 -3
  121. package/source/types/basewithoptions.js +3 -3
  122. package/source/types/global.js +7 -7
  123. package/source/types/id.js +3 -3
  124. package/source/types/is.js +30 -30
  125. package/source/types/namespace.js +3 -2
  126. package/source/types/observer.js +4 -4
  127. package/source/types/observerlist.js +3 -3
  128. package/source/types/proxyobserver.js +6 -6
  129. package/source/types/queue.js +4 -4
  130. package/source/types/randomid.js +3 -3
  131. package/source/types/stack.js +3 -3
  132. package/source/types/tokenlist.js +3 -3
  133. package/source/types/typeof.js +4 -4
  134. package/source/types/uniquequeue.js +3 -3
  135. package/source/types/validate.js +34 -34
  136. package/source/types/version.js +7 -7
  137. package/source/util/clone.js +3 -3
  138. package/source/util/comparator.js +37 -7
  139. package/source/util/freeze.js +4 -4
  140. package/source/util/namespace.js +3 -2
  141. package/test/cases/data/buildmap.js +242 -16
  142. package/test/cases/data/diff.js +36 -3
  143. package/test/cases/data/pathfinder.js +298 -196
  144. package/test/cases/logging/handler/console.js +20 -0
  145. package/test/cases/monster.js +1 -1
  146. package/test/web/import.js +1 -0
  147. package/test/web/monster-dev.html +3 -3
  148. package/test/web/monster.html +2 -2
  149. package/test/web/test.html +2 -2
  150. package/test/web/tests.js +3 -3
@@ -1,28 +1,254 @@
1
1
  "use strict";
2
2
 
3
- import {buildMap} from "../../../source/data/buildmap.js";
4
3
  import {expect} from "chai"
4
+ import {buildMap} from "../../../source/data/buildmap.js";
5
5
 
6
6
 
7
7
  describe('buildMap', function () {
8
8
 
9
- function mapToObj(map) {
10
- var obj = {}
11
- map.forEach(function (v, k) {
12
- if (v instanceof Map) {
13
- obj[k] = mapToObj(v)
14
- } else {
15
- obj[k] = v
9
+ let convertMapResult = function (r) {
10
+ if (r instanceof Map) {
11
+ r = Object.fromEntries(r);
12
+ if (r instanceof Array) {
13
+ r = r.map((e) => {
14
+ return convertMapResult(e);
15
+ })
16
+ } else if (typeof r === "object") {
17
+ for (const [k, o] of Object.entries(r)) {
18
+ r[k] = convertMapResult(o);
19
+ }
16
20
  }
21
+ }
17
22
 
18
- })
19
- return obj
23
+ return r;
20
24
  }
21
25
 
26
+ describe('build Map with callback', function () {
27
+ it('definition should return map with sub and parent keys', function () {
28
+
29
+ let obj = {
30
+ "data": [
31
+ {
32
+ "id": 10,
33
+ "name": "Cassandra",
34
+ "enrichment": {
35
+ variants: [
36
+ {
37
+ sku: 1, label: "XXS", price: [
38
+ {vk: '12.12 €'},
39
+ {vk: '12.12 €'}
40
+ ]
41
+ },
42
+ {
43
+ sku: 2, label: "XS", price: [
44
+ {vk: '22.12 €'},
45
+ {vk: '22.12 €'}
46
+ ]
47
+ },
48
+ {
49
+ sku: 3, label: "S", price: [
50
+ {vk: '32.12 €'},
51
+ {vk: '32.12 €'}
52
+ ]
53
+ },
54
+ {
55
+ sku: 4, label: "L", price: [
56
+ {vk: '42.12 €'},
57
+ {vk: '42.12 €'}
58
+ ]
59
+ }
60
+ ]
61
+
62
+ }
63
+ },
64
+ {
65
+ "id": 20,
66
+ "name": "Yessey!",
67
+ "enrichment": {
68
+ variants: [
69
+ {
70
+ sku: 1, label: "XXS", price: [
71
+ {vk: '12.12 €'},
72
+ {vk: '12.12 €'}
73
+ ]
74
+ },
75
+ {
76
+ sku: 2, label: "XS", price: [
77
+ {vk: '22.12 €'},
78
+ {vk: '22.12 €'}
79
+ ]
80
+ },
81
+ {
82
+ sku: 3, label: "S", price: [
83
+ {vk: '32.12 €'},
84
+ {vk: '32.12 €'}
85
+ ]
86
+ },
87
+ {
88
+ sku: 4, label: "L", price: [
89
+ {vk: '42.12 €'},
90
+ {vk: '42.12 €'}
91
+ ]
92
+ }
93
+ ]
94
+
95
+ }
96
+ }
97
+ ]
98
+ };
99
+
100
+ let callback = function (subject) {
101
+ let m = new Map;
102
+
103
+ for (const [i, b] of Object.entries(subject.data)) {
104
+
105
+ let key1 = i;
106
+
107
+ for (const [j, c] of Object.entries(b.enrichment.variants)) {
108
+ let key2 = j;
109
+
110
+ for (const [k, d] of Object.entries(c.price)) {
111
+
112
+ let key3 = k;
113
+
114
+ d.name = b.name;
115
+ d.label = c.label;
116
+ d.id = [key1, key2, key3].join('.');
117
+
118
+ m.set(d.id, d);
119
+ }
120
+
121
+ }
122
+ }
123
+ return m;
124
+ }
125
+
126
+ let map = buildMap(obj, callback, '${name} ${label}', '${id}')
127
+ let i = convertMapResult(map);
128
+
129
+ expect(JSON.stringify(i)).to.be.equal('{"0.0.0":"Cassandra XXS","0.0.1":"Cassandra XXS","0.1.0":"Cassandra XS","0.1.1":"Cassandra XS","0.2.0":"Cassandra S","0.2.1":"Cassandra S","0.3.0":"Cassandra L","0.3.1":"Cassandra L","1.0.0":"Yessey! XXS","1.0.1":"Yessey! XXS","1.1.0":"Yessey! XS","1.1.1":"Yessey! XS","1.2.0":"Yessey! S","1.2.1":"Yessey! S","1.3.0":"Yessey! L","1.3.1":"Yessey! L"}');
130
+
131
+ })
132
+ })
133
+
134
+ describe('build submap with *', function () {
135
+ it('definition should return {"10":"Cassandra 10","20":"Yessey! 20"}', function () {
136
+
137
+ let obj = {
138
+ "data": [
139
+ {
140
+ "id": 10,
141
+ "name": "Cassandra"
142
+ },
143
+ {
144
+ "id": 20,
145
+ "name": "Yessey!",
146
+ }
147
+ ]
148
+ };
149
+
150
+ let map = buildMap(obj, 'data.*', '${name} ${id}', '${id}')
151
+ let i = convertMapResult(map);
152
+ expect(JSON.stringify(i)).to.be.equal('{"10":"Cassandra 10","20":"Yessey! 20"}');
153
+
154
+ })
155
+ })
156
+
157
+
158
+ describe('build submap with **', function () {
159
+ it('definition should return Map', function () {
160
+
161
+ let obj = {
162
+ "data": [
163
+ {
164
+ "id": 10,
165
+ "name": "Cassandra",
166
+ "enrichment": {
167
+ variants: [
168
+ {
169
+ sku: 1, label: "XXS",
170
+ price: [
171
+ {vk: '12.12 €', id: 1},
172
+ {vk: '12.12 €', id: 2}
173
+ ]
174
+ },
175
+ {
176
+ sku: 2, label: "XS",
177
+ price: [
178
+ {vk: '22.12 €', id: 3},
179
+ {vk: '22.12 €', id: 4}
180
+ ]
181
+ },
182
+ {
183
+ sku: 3, label: "S",
184
+ price: [
185
+ {vk: '32.12 €', id: 5},
186
+ {vk: '32.12 €', id: 6}
187
+ ]
188
+ },
189
+ {
190
+ sku: 4, label: "L",
191
+ price: [
192
+ {vk: '42.12 €', id: 7},
193
+ {vk: '42.12 €', id: 8}
194
+ ]
195
+ }
196
+ ]
197
+
198
+ }
199
+ },
200
+ {
201
+ "id": 20,
202
+ "name": "Yessey!",
203
+ "enrichment": {
204
+ variants: [
205
+ {
206
+ sku: 1, label: "XXS",
207
+ price: [
208
+ {vk: '12.12 €', id: 9},
209
+ {vk: '12.12 €', id: 10}
210
+ ]
211
+ },
212
+ {
213
+ sku: 2, label: "XS",
214
+ price: [
215
+ {vk: '22.12 €', id: 11},
216
+ {vk: '22.12 €', id: 12}
217
+ ]
218
+ },
219
+ {
220
+ sku: 3, label: "S",
221
+ price: [
222
+ {vk: '32.12 €', id: 13},
223
+ {vk: '32.12 €', id: 14}
224
+ ]
225
+ },
226
+ {
227
+ sku: 4,
228
+ label: "L",
229
+ price: [
230
+ {vk: '42.12 €', id: 15},
231
+ {vk: '42.12 €', id: 16},
232
+ {vk: '44.12 €', id: 17}
233
+ ]
234
+ }
235
+ ]
236
+
237
+ }
238
+ }
239
+ ]
240
+ };
241
+
242
+ let map = buildMap(obj, 'data.*.enrichment.variants.*.price.*', '${vk} ${^.label} ${^.^.name}', '${^.^.sku}')
243
+ let i = convertMapResult(map);
244
+ expect(JSON.stringify(i)).to.be.equal('{"data.0.enrichment.variants.0.price.0":"12.12 € XXS Cassandra","data.0.enrichment.variants.0.price.1":"12.12 € XXS Cassandra","data.0.enrichment.variants.1.price.0":"22.12 € XS Cassandra","data.0.enrichment.variants.1.price.1":"22.12 € XS Cassandra","data.0.enrichment.variants.2.price.0":"32.12 € S Cassandra","data.0.enrichment.variants.2.price.1":"32.12 € S Cassandra","data.0.enrichment.variants.3.price.0":"42.12 € L Cassandra","data.0.enrichment.variants.3.price.1":"42.12 € L Cassandra","data.1.enrichment.variants.0.price.0":"12.12 € XXS Yessey!","data.1.enrichment.variants.0.price.1":"12.12 € XXS Yessey!","data.1.enrichment.variants.1.price.0":"22.12 € XS Yessey!","data.1.enrichment.variants.1.price.1":"22.12 € XS Yessey!","data.1.enrichment.variants.2.price.0":"32.12 € S Yessey!","data.1.enrichment.variants.2.price.1":"32.12 € S Yessey!","data.1.enrichment.variants.3.price.0":"42.12 € L Yessey!","data.1.enrichment.variants.3.price.1":"42.12 € L Yessey!","data.1.enrichment.variants.3.price.2":"44.12 € L Yessey!"}');
245
+
246
+ })
247
+ })
22
248
 
23
249
  describe('examplecode', function () {
24
250
 
25
- it('definition should return Map Instance', function () {
251
+ it('should execute example code', function () {
26
252
 
27
253
  let obj = {
28
254
  "data": [
@@ -56,7 +282,7 @@ describe('buildMap', function () {
56
282
  ]
57
283
  };
58
284
 
59
- let map = buildMap(obj, 'data.*', '${name} (${address.zip} ${address.city})', '${id}')
285
+ let map;
60
286
  map = buildMap(obj, 'data.*', '${name} (${address.zip} ${address.city})', 'id')
61
287
  expect(map).to.be.instanceOf(Map);
62
288
 
@@ -86,15 +312,15 @@ describe('buildMap', function () {
86
312
  }
87
313
  };
88
314
 
89
- it('should return Map Instance', function () {
315
+ it('should return Map Instance.', function () {
90
316
  expect(buildMap({}, '')).to.be.instanceOf(Map);
91
317
  });
92
318
 
93
319
 
94
320
  [
95
- [obj1, 'dataset.*', 'address', '{"10082":"Here 1","10084":"Here 2"}'],
321
+ [obj1, 'dataset.*', 'address', '{"dataset.10082":"Here 1","dataset.10084":"Here 2"}'],
96
322
  [obj1, 'x', undefined, '{}'],
97
- [obj1, 'dataset.*', 'name', '{"10082":"Test 1","10084":"Test 2"}'],
323
+ [obj1, 'dataset.*', 'name', '{"dataset.10082":"Test 1","dataset.10084":"Test 2"}'],
98
324
  ].forEach(function (data) {
99
325
 
100
326
  let a = data.shift()
@@ -104,7 +330,7 @@ describe('buildMap', function () {
104
330
 
105
331
  it('buildMap(' + JSON.stringify(a) + ',' + JSON.stringify(b) + ',' + JSON.stringify(c) + ') should return ' + JSON.stringify(d) + ' ', function () {
106
332
  let t = buildMap(a, b, c);
107
- let m = JSON.stringify(mapToObj(t));
333
+ let m = JSON.stringify(convertMapResult(t));
108
334
  expect(m).to.be.equal(d);
109
335
  });
110
336
  });
@@ -1,11 +1,44 @@
1
1
  "use strict";
2
2
 
3
- import {Diff} from "../../../source/data/diff.js";
4
3
  import {expect} from "chai"
4
+ import {Diff} from "../../../source/data/diff.js";
5
5
  import {Queue} from "../../../source/types/queue.js";
6
6
 
7
7
  describe('Diff', function () {
8
8
 
9
+ describe('Diff special cases', function () {
10
+
11
+ var obj1, obj2;
12
+
13
+ beforeEach(() => {
14
+ obj1 = {
15
+ "count": 1,
16
+ "reason": null,
17
+ "info": "test",
18
+ "exchange": []
19
+ };
20
+ obj2 = {
21
+ "count": 2,
22
+ "reason": null,
23
+ "info": undefined,
24
+ "exchange": []
25
+ };
26
+
27
+ });
28
+
29
+ it('Diff value with null ', function () {
30
+ let d = Diff(obj1, obj2);
31
+ expect(JSON.stringify(d)).is.equal('[{"operator":"update","path":["count"],"first":{"value":1,"type":"number"},"second":{"value":2,"type":"number"}},{"operator":"delete","path":["info"],"first":{"value":"test","type":"string"}},{"operator":"update","path":["exchange"],"first":{"value":[],"type":"object"},"second":{"value":[],"type":"object"}}]');
32
+ });
33
+
34
+ it('Diff identical value with null ', function () {
35
+ let d = Diff(obj1, obj1);
36
+ expect(JSON.stringify(d)).is.equal('[]');
37
+ });
38
+
39
+
40
+ })
41
+
9
42
  const date1 = new Date;
10
43
 
11
44
  // https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Date/parse
@@ -102,7 +135,7 @@ describe('Diff', function () {
102
135
  a: 2
103
136
  },
104
137
  '[{"operator":"update","path":["a"],"first":{"value":1,"type":"number"},"second":{"value":2,"type":"number"}}]'
105
- ],
138
+ ],
106
139
 
107
140
  [
108
141
  {
@@ -133,7 +166,7 @@ describe('Diff', function () {
133
166
  let c = data.shift()
134
167
 
135
168
 
136
- it('Diff should result '+c, function () {
169
+ it('Diff should result ' + c, function () {
137
170
  let d = Diff(a, b);
138
171
  expect(JSON.stringify(d)).is.equal(c);
139
172
  });