@schukai/monster 1.21.1 → 1.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. package/CHANGELOG +48 -1
  2. package/README.md +4 -4
  3. package/dist/modules/constants.js +2 -2
  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 +1 -1
  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 +1 -1
  14. package/dist/modules/data/datasource/namespace.js +2 -0
  15. package/dist/modules/data/datasource/restapi/writeerror.js +2 -0
  16. package/dist/modules/data/datasource/restapi.js +2 -0
  17. package/dist/modules/data/datasource/storage/localstorage.js +2 -0
  18. package/dist/modules/data/datasource/storage/namespace.js +2 -0
  19. package/dist/modules/data/datasource/storage/sessionstorage.js +2 -0
  20. package/dist/modules/data/datasource/storage.js +2 -0
  21. package/dist/modules/data/datasource.js +2 -0
  22. package/dist/modules/data/diff.js +2 -2
  23. package/dist/modules/data/extend.js +1 -1
  24. package/dist/modules/data/namespace.js +1 -1
  25. package/dist/modules/data/pathfinder.js +2 -2
  26. package/dist/modules/data/pipe.js +1 -1
  27. package/dist/modules/data/transformer.js +2 -2
  28. package/dist/modules/dom/assembler.js +1 -1
  29. package/dist/modules/dom/attributes.js +1 -1
  30. package/dist/modules/dom/constants.js +2 -2
  31. package/dist/modules/dom/customcontrol.js +2 -2
  32. package/dist/modules/dom/customelement.js +2 -2
  33. package/dist/modules/dom/events.js +1 -1
  34. package/dist/modules/dom/focusmanager.js +2 -0
  35. package/dist/modules/dom/locale.js +1 -1
  36. package/dist/modules/dom/namespace.js +1 -1
  37. package/dist/modules/dom/resource/data.js +2 -0
  38. package/dist/modules/dom/resource/link/stylesheet.js +2 -0
  39. package/dist/modules/dom/resource/link.js +2 -0
  40. package/dist/modules/dom/resource/script.js +2 -0
  41. package/dist/modules/dom/resource.js +2 -0
  42. package/dist/modules/dom/resourcemanager.js +2 -0
  43. package/dist/modules/dom/template.js +1 -1
  44. package/dist/modules/dom/theme.js +1 -1
  45. package/dist/modules/dom/updater.js +2 -2
  46. package/dist/modules/dom/util.js +1 -1
  47. package/dist/modules/dom/worker/factory.js +2 -0
  48. package/dist/modules/i18n/locale.js +1 -1
  49. package/dist/modules/i18n/namespace.js +1 -1
  50. package/dist/modules/i18n/provider.js +1 -1
  51. package/dist/modules/i18n/providers/fetch.js +2 -2
  52. package/dist/modules/i18n/providers/namespace.js +1 -1
  53. package/dist/modules/i18n/translations.js +1 -1
  54. package/dist/modules/logging/handler/console.js +1 -1
  55. package/dist/modules/logging/handler/namespace.js +1 -1
  56. package/dist/modules/logging/handler.js +1 -1
  57. package/dist/modules/logging/logentry.js +1 -1
  58. package/dist/modules/logging/logger.js +1 -1
  59. package/dist/modules/logging/namespace.js +1 -1
  60. package/dist/modules/math/namespace.js +1 -1
  61. package/dist/modules/math/random.js +2 -2
  62. package/dist/modules/monster.js +1 -1
  63. package/dist/modules/namespace.js +1 -1
  64. package/dist/modules/text/formatter.js +2 -2
  65. package/dist/modules/text/namespace.js +1 -1
  66. package/dist/modules/types/base.js +1 -1
  67. package/dist/modules/types/basewithoptions.js +2 -2
  68. package/dist/modules/types/binary.js +1 -1
  69. package/dist/modules/types/dataurl.js +1 -1
  70. package/dist/modules/types/global.js +1 -1
  71. package/dist/modules/types/id.js +1 -1
  72. package/dist/modules/types/is.js +1 -1
  73. package/dist/modules/types/mediatype.js +1 -1
  74. package/dist/modules/types/namespace.js +1 -1
  75. package/dist/modules/types/observer.js +1 -1
  76. package/dist/modules/types/observerlist.js +2 -2
  77. package/dist/modules/types/proxyobserver.js +2 -2
  78. package/dist/modules/types/queue.js +1 -1
  79. package/dist/modules/types/randomid.js +1 -1
  80. package/dist/modules/types/stack.js +1 -1
  81. package/dist/modules/types/tokenlist.js +2 -2
  82. package/dist/modules/types/typeof.js +1 -1
  83. package/dist/modules/types/uniquequeue.js +1 -1
  84. package/dist/modules/types/uuid.js +2 -0
  85. package/dist/modules/types/validate.js +1 -1
  86. package/dist/modules/types/version.js +2 -2
  87. package/dist/modules/util/clone.js +2 -2
  88. package/dist/modules/util/comparator.js +2 -2
  89. package/dist/modules/util/freeze.js +1 -1
  90. package/dist/modules/util/namespace.js +1 -1
  91. package/dist/modules/util/processing.js +2 -2
  92. package/dist/modules/util/trimspaces.js +2 -0
  93. package/dist/monster.dev.js +1499 -732
  94. package/dist/monster.dev.js.map +1 -1
  95. package/dist/monster.js +2 -2
  96. package/package.json +1 -1
  97. package/source/constants.js +16 -7
  98. package/source/constraints/andoperator.js +5 -5
  99. package/source/constraints/invalid.js +3 -3
  100. package/source/constraints/isarray.js +3 -3
  101. package/source/constraints/isobject.js +3 -3
  102. package/source/constraints/oroperator.js +5 -5
  103. package/source/constraints/valid.js +3 -3
  104. package/source/data/buildmap.js +6 -6
  105. package/source/data/datasource/namespace.js +16 -0
  106. package/source/data/datasource/restapi/writeerror.js +49 -0
  107. package/source/data/datasource/restapi.js +266 -0
  108. package/source/data/datasource/storage/localstorage.js +64 -0
  109. package/source/data/datasource/storage/namespace.js +16 -0
  110. package/source/data/datasource/storage/sessionstorage.js +61 -0
  111. package/source/data/datasource/storage.js +131 -0
  112. package/source/data/datasource.js +246 -0
  113. package/source/data/diff.js +8 -8
  114. package/source/data/extend.js +5 -5
  115. package/source/data/pathfinder.js +12 -6
  116. package/source/data/pipe.js +6 -5
  117. package/source/data/transformer.js +131 -24
  118. package/source/dom/assembler.js +2 -2
  119. package/source/dom/attributes.js +24 -24
  120. package/source/dom/constants.js +305 -12
  121. package/source/dom/customcontrol.js +40 -19
  122. package/source/dom/customelement.js +182 -103
  123. package/source/dom/events.js +6 -6
  124. package/source/dom/focusmanager.js +251 -0
  125. package/source/dom/locale.js +4 -3
  126. package/source/dom/resource/data.js +170 -0
  127. package/source/dom/resource/link/stylesheet.js +54 -0
  128. package/source/dom/resource/link.js +125 -0
  129. package/source/dom/resource/script.js +112 -0
  130. package/source/dom/resource.js +268 -0
  131. package/source/dom/resourcemanager.js +214 -0
  132. package/source/dom/template.js +40 -10
  133. package/source/dom/theme.js +3 -3
  134. package/source/dom/updater.js +114 -58
  135. package/source/dom/util.js +6 -6
  136. package/source/dom/worker/factory.js +134 -0
  137. package/source/i18n/locale.js +8 -8
  138. package/source/i18n/provider.js +4 -4
  139. package/source/i18n/providers/fetch.js +8 -13
  140. package/source/i18n/translations.js +6 -5
  141. package/source/logging/handler/console.js +2 -2
  142. package/source/logging/handler.js +2 -2
  143. package/source/logging/logentry.js +2 -2
  144. package/source/logging/logger.js +4 -4
  145. package/source/math/random.js +11 -5
  146. package/source/namespace.js +1 -1
  147. package/source/text/formatter.js +82 -7
  148. package/source/types/base.js +4 -4
  149. package/source/types/basewithoptions.js +10 -15
  150. package/source/types/binary.js +8 -8
  151. package/source/types/dataurl.js +6 -6
  152. package/source/types/global.js +9 -7
  153. package/source/types/id.js +2 -2
  154. package/source/types/is.js +23 -23
  155. package/source/types/mediatype.js +4 -4
  156. package/source/types/observer.js +3 -3
  157. package/source/types/observerlist.js +3 -3
  158. package/source/types/proxyobserver.js +24 -7
  159. package/source/types/queue.js +5 -5
  160. package/source/types/randomid.js +2 -2
  161. package/source/types/stack.js +2 -2
  162. package/source/types/tokenlist.js +8 -9
  163. package/source/types/typeof.js +3 -3
  164. package/source/types/uniquequeue.js +4 -4
  165. package/source/types/uuid.js +102 -0
  166. package/source/types/validate.js +20 -20
  167. package/source/types/version.js +6 -6
  168. package/source/util/clone.js +5 -6
  169. package/source/util/comparator.js +5 -5
  170. package/source/util/freeze.js +5 -5
  171. package/source/util/processing.js +33 -36
  172. package/source/util/trimspaces.js +85 -0
  173. package/test/cases/data/datasource/restapi.js +89 -0
  174. package/test/cases/data/datasource/storage/localstorage.js +47 -0
  175. package/test/cases/data/datasource/storage/sessionstorage.js +47 -0
  176. package/test/cases/data/datasource.js +60 -0
  177. package/test/cases/data/diff.js +4 -4
  178. package/test/cases/data/pathfinder.js +18 -9
  179. package/test/cases/data/pipe.js +26 -2
  180. package/test/cases/data/transformer.js +41 -10
  181. package/test/cases/dom/customcontrol.js +6 -5
  182. package/test/cases/dom/customelement.js +25 -26
  183. package/test/cases/dom/focusmanager.js +111 -0
  184. package/test/cases/dom/locale.js +1 -4
  185. package/test/cases/dom/resource/data.js +129 -0
  186. package/test/cases/dom/resource/link/stylesheet.js +101 -0
  187. package/test/cases/dom/resource/link.js +101 -0
  188. package/test/cases/dom/resource/script.js +115 -0
  189. package/test/cases/dom/resourcemanager.js +118 -0
  190. package/test/cases/dom/updater.js +42 -19
  191. package/test/cases/dom/worker/factory.js +63 -0
  192. package/test/cases/monster.js +1 -1
  193. package/test/cases/text/formatter.js +38 -6
  194. package/test/cases/types/proxyobserver.js +55 -11
  195. package/test/cases/types/uuid.js +42 -0
  196. package/test/cases/util/freeze.js +30 -4
  197. package/test/cases/util/trimspaces.js +24 -0
  198. package/test/util/cleanupdom.js +48 -0
  199. package/test/util/jsdom.js +23 -9
  200. package/test/util/localstorage.js +81 -0
  201. package/test/web/import.js +13 -0
  202. package/test/web/monster-dev.html +3 -3
  203. package/test/web/monster.html +2 -2
  204. package/test/web/test.html +3 -3
  205. package/test/web/tests.js +7 -7
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ import {expect} from "chai"
4
+ import {RestAPI} from "../../../../source/data/datasource/restapi.js";
5
+ import {validateObject} from "../../../../source/types/validate.js";
6
+
7
+
8
+ describe('RestAPI', function () {
9
+
10
+ let fetchReference;
11
+ let returnStatus;
12
+
13
+ afterEach(() => {
14
+ global['fetch'] = fetchReference;
15
+ });
16
+
17
+ beforeEach(() => {
18
+
19
+ returnStatus = 200;
20
+ fetchReference = global['fetch'];
21
+ global['fetch'] = function (url, options) {
22
+
23
+ if (!url) throw new Error('missing url')
24
+
25
+ return new Promise((resolve, reject) => {
26
+ resolve({
27
+ text: function () {
28
+ return JSON.stringify({
29
+ a: "test"
30
+ })
31
+ },
32
+ status: returnStatus
33
+ });
34
+ })
35
+
36
+ };
37
+
38
+ })
39
+
40
+ it('should instance of RestAPI ', function () {
41
+ expect(new RestAPI('https://monsterjs.org/assets/world.json')).to.be.instanceof(RestAPI)
42
+ });
43
+
44
+ describe('rw', function () {
45
+
46
+ it('read should return object', function (done) {
47
+ const ds = new RestAPI({url: 'https://monsterjs.org/assets/world.json'})
48
+ ds.read().then(data => {
49
+ validateObject(data);
50
+ done();
51
+ }).catch(e => done(e));
52
+ });
53
+
54
+ it('write should ', function (done) {
55
+ const ds = new RestAPI({url: 'https://monsterjs.org/assets/world.json'}, {url: 'https://monsterjs.org/assets/world.json'})
56
+ ds.write().then(data => {
57
+ validateObject(data);
58
+ done();
59
+ }).catch(e => done(e));
60
+ });
61
+
62
+
63
+ })
64
+
65
+ describe('rw with errors', function () {
66
+
67
+ it('read should throw exception', function (done) {
68
+ returnStatus = 400; // fetch response with 400
69
+
70
+ const ds = new RestAPI({url: 'https://monsterjs.org/assets/world.json'})
71
+ ds.read().then(data => {
72
+ done("should not run.");
73
+ }).catch(e => done()); // should throw exception because returnStatus=400
74
+ });
75
+
76
+ it('write should ', function (done) {
77
+ returnStatus = 400; // fetch response with 400
78
+ const ds = new RestAPI({url: 'https://monsterjs.org/assets/world.json'}, {url: 'https://monsterjs.org/assets/world.json'})
79
+ ds.write().then(data => {
80
+ validateObject(data);
81
+ done("error");
82
+ }).catch(e => done()); // should throw exception because returnStatus=400
83
+ });
84
+
85
+
86
+ })
87
+
88
+
89
+ })
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ import {expect} from "chai"
4
+ import {LocalStorage} from "../../../../../source/data/datasource/storage/localstorage.js";
5
+ import {createStorage} from "../../../../util/localstorage.js";
6
+
7
+
8
+ let localStorageReference;
9
+
10
+ describe('LocalStorage', function () {
11
+
12
+ afterEach(() => {
13
+ global['localStorage'] = localStorageReference;
14
+ });
15
+
16
+ beforeEach(function () {
17
+
18
+ localStorageReference = global['localStorage']
19
+ global['localStorage'] = createStorage();
20
+
21
+ })
22
+
23
+ it('should instance of LocalStorage ', function () {
24
+ expect(new LocalStorage('mykey')).to.be.instanceof(LocalStorage)
25
+ });
26
+
27
+ describe('rw', function () {
28
+
29
+ it('read should return object', function (done) {
30
+ const ds = new LocalStorage('mykey')
31
+ ds.read().then(data => {
32
+ done();
33
+ }).catch(e => done(e));
34
+ });
35
+
36
+ it('write should ', function (done) {
37
+ const ds = new LocalStorage('mykey')
38
+ ds.write().then(data => {
39
+ done();
40
+ }).catch(e => done(e));
41
+ });
42
+
43
+
44
+ })
45
+
46
+
47
+ })
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ import {expect} from "chai"
4
+ import {SessionStorage} from "../../../../../source/data/datasource/storage/sessionstorage.js";
5
+ import {createStorage} from "../../../../util/localstorage.js";
6
+
7
+
8
+ let storageReference;
9
+
10
+ describe('SessionStorage', function () {
11
+
12
+ afterEach(() => {
13
+ global['sessionStorage'] = storageReference;
14
+ });
15
+
16
+ beforeEach(function () {
17
+
18
+ storageReference = global['sessionStorage']
19
+ global['sessionStorage'] = createStorage();
20
+
21
+ })
22
+
23
+ it('should instance of SessionStorage ', function () {
24
+ expect(new SessionStorage('mykey')).to.be.instanceof(SessionStorage)
25
+ });
26
+
27
+ describe('rw', function () {
28
+
29
+ it('read should return object', function (done) {
30
+ const ds = new SessionStorage('mykey')
31
+ ds.read().then(data => {
32
+ done();
33
+ }).catch(e => done(e));
34
+ });
35
+
36
+ it('write should ', function (done) {
37
+ const ds = new SessionStorage('mykey')
38
+ ds.write().then(data => {
39
+ done();
40
+ }).catch(e => done(e));
41
+ });
42
+
43
+
44
+ })
45
+
46
+
47
+ })
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ import {expect} from "chai"
4
+ import {Datasource} from "../../../source/data/datasource.js";
5
+
6
+
7
+ describe('Datasource', function () {
8
+
9
+
10
+ it('should instance of Datasource ', function () {
11
+ expect(new Datasource()).to.be.instanceof(Datasource)
12
+ });
13
+
14
+ describe('Options', function () {
15
+ it('setOption should change value', function () {
16
+ const datasource = new Datasource();
17
+ expect(datasource.getOption('default')).to.be.undefined
18
+ datasource.setOption('default', true)
19
+ expect(datasource.getOption('default')).to.be.true
20
+ });
21
+
22
+ it('setOptions should set all values', function () {
23
+ const datasource = new Datasource();
24
+ expect(datasource.getOption('default')).to.be.undefined
25
+ datasource.setOptions({default: true})
26
+ expect(datasource.getOption('default')).to.be.true
27
+ });
28
+
29
+ })
30
+
31
+ describe('rw', function () {
32
+ const datasource = new Datasource();
33
+ it('read should throw exeption', function () {
34
+ expect(() => datasource.read()).to.throw(Error);
35
+ });
36
+
37
+ it('write should throw exeption', function () {
38
+ expect(() => datasource.read()).to.throw(Error);
39
+ });
40
+
41
+
42
+ })
43
+
44
+ describe('get/set', function () {
45
+ const datasource = new Datasource();
46
+ it('get should return undefined', function () {
47
+ expect( datasource.get()).to.be.eql({});
48
+ });
49
+
50
+ it('write should throw exeption', function () {
51
+ expect( datasource.get()).to.be.eql({});
52
+ expect( datasource.set({a:'myvalue'})).to.be.instanceof(Datasource);
53
+ expect( datasource.get()).to.be.eql({a:'myvalue'});
54
+ });
55
+
56
+
57
+ })
58
+
59
+
60
+ })
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  import {expect} from "chai"
4
- import {Diff} from "../../../source/data/diff.js";
4
+ import {diff} from "../../../source/data/diff.js";
5
5
  import {Queue} from "../../../source/types/queue.js";
6
6
 
7
7
  describe('Diff', function () {
@@ -27,12 +27,12 @@ describe('Diff', function () {
27
27
  });
28
28
 
29
29
  it('Diff value with null ', function () {
30
- let d = Diff(obj1, obj2);
30
+ let d = diff(obj1, obj2);
31
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"}}]');
32
32
  });
33
33
 
34
34
  it('Diff identical value with null ', function () {
35
- let d = Diff(obj1, obj1);
35
+ let d = diff(obj1, obj1);
36
36
  expect(JSON.stringify(d)).is.equal('[]');
37
37
  });
38
38
 
@@ -194,7 +194,7 @@ describe('Diff', function () {
194
194
 
195
195
 
196
196
  it('Diff should result ' + c, function () {
197
- let d = Diff(a, b);
197
+ let d = diff(a, b);
198
198
  expect(JSON.stringify(d)).is.equal(c);
199
199
  });
200
200
 
@@ -85,6 +85,13 @@ describe('Pathfinder', function () {
85
85
 
86
86
  let pathfinder, object;
87
87
 
88
+
89
+ class A {
90
+ get a() {
91
+ return 1
92
+ }
93
+ }
94
+
88
95
  beforeEach(() => {
89
96
 
90
97
  object = {
@@ -106,7 +113,8 @@ describe('Pathfinder', function () {
106
113
  k: (new Map).set('m', {n: 3}),
107
114
  l: (new Set).add({n: 4})
108
115
  }
109
- }
116
+ },
117
+ b: new A
110
118
  };
111
119
 
112
120
  pathfinder = new Pathfinder(object);
@@ -186,25 +194,24 @@ describe('Pathfinder', function () {
186
194
 
187
195
  it('.setVia(' + a + ', ' + b + ') should change object', function () {
188
196
  pathfinder.setVia(a, b);
189
- expect(JSON.stringify(object)).is.equal('{"a":{"b":{"c":[4,"test1",false,null,null],"e":false,"f":[{"g":false,"h":3,"i":["test2"]}],"j":{},"k":{},"l":{}},"x":"true"}}');
197
+ expect(JSON.stringify(object)).is.equal('{"a":{"b":{"c":[4,"test1",false,null,null],"e":false,"f":[{"g":false,"h":3,"i":["test2"]}],"j":{},"k":{},"l":{}},"x":"true"},"b":{}}');
190
198
  });
191
199
 
192
200
  it('.setVia(' + c + ', ' + b + ') should change object', function () {
193
201
  pathfinder.setVia(c, b);
194
- expect(JSON.stringify(object)).is.equal('{"a":{"b":{"c":[4,"test1",false,null,null],"e":false,"f":[{"g":false,"h":3,"i":["test2"]}],"j":{},"k":{},"l":{}},"y":{"d":"true"}}}');
202
+ expect(JSON.stringify(object)).is.equal('{"a":{"b":{"c":[4,"test1",false,null,null],"e":false,"f":[{"g":false,"h":3,"i":["test2"]}],"j":{},"k":{},"l":{}},"y":{"d":"true"}},"b":{}}');
195
203
  });
196
204
 
197
205
  });
198
206
 
199
207
 
200
208
  describe('.exists()', function () {
201
-
202
-
203
209
  [
210
+ ['a.b.c.1', true],
211
+ ['b.a', true],
204
212
  ['a.b.x', false],
205
213
  ['a.x', false],
206
214
  ['a.b.q', false],
207
- ['a.b.c.1', true],
208
215
  ['a.b.c.0', true],
209
216
  ['a.b.d', true],
210
217
  ['a.b.f.0.g', true],
@@ -224,13 +231,14 @@ describe('Pathfinder', function () {
224
231
 
225
232
  });
226
233
 
234
+
227
235
  });
228
236
 
229
237
  describe('.deleteVia()', function () {
230
238
  [
231
- ['a.b.e', '{"a":{"b":{"c":[4,"test1",false,null,null],"f":[{"g":false,"h":3,"i":["test2"]}],"j":{},"k":{},"l":{}}}}'],
232
- ['a.b.f', '{"a":{"b":{"c":[4,"test1",false,null,null],"e":false,"j":{},"k":{},"l":{}}}}'],
233
- ['a.b.j', '{"a":{"b":{"c":[4,"test1",false,null,null],"e":false,"f":[{"g":false,"h":3,"i":["test2"]}],"k":{},"l":{}}}}'],
239
+ ['a.b.e', '{"a":{"b":{"c":[4,"test1",false,null,null],"f":[{"g":false,"h":3,"i":["test2"]}],"j":{},"k":{},"l":{}}},"b":{}}'],
240
+ ['a.b.f', '{"a":{"b":{"c":[4,"test1",false,null,null],"e":false,"j":{},"k":{},"l":{}}},"b":{}}'],
241
+ ['a.b.j', '{"a":{"b":{"c":[4,"test1",false,null,null],"e":false,"f":[{"g":false,"h":3,"i":["test2"]}],"k":{},"l":{}}},"b":{}}'],
234
242
 
235
243
  ].forEach(function (data) {
236
244
 
@@ -291,6 +299,7 @@ describe('Pathfinder', function () {
291
299
  });
292
300
 
293
301
  [
302
+ ['a.*', '[["b",{"c":[4,"test1",false,null,null],"e":false,"f":[{"g":false,"h":3,"i":["test2"]}],"j":{},"k":{},"l":{},"o":[{"p":{"q":1,"r":true}},{"p":{"q":2,"r":true}},{"p":{"q":3,"r":true}},{"p":{"q":4,"r":true}},{"p":{"q":5,"r":true}}],"s":{"t":{"a":1},"u":{"a":2},"v":{"a":3},"x":{"a":4}}}]]'],
294
303
  ['a.b.s.*.a', '[["t",1],["u",2],["v",3],["x",4]]'],
295
304
  ['a.b.s.*', '[["t",{"a":1}],["u",{"a":2}],["v",{"a":3}],["x",{"a":4}]]'],
296
305
  ['a.b.o.*.p.q', '[["0",1],["1",2],["2",3],["3",4],["4",5]]'],
@@ -1,14 +1,38 @@
1
1
  "use strict";
2
2
 
3
- import {Pipe} from "../../../source/data/pipe.js";
4
- import {expect} from "chai"
5
3
  import * as Crypto from "@peculiar/webcrypto";
4
+ import {expect} from "chai"
5
+ import {Pipe} from "../../../source/data/pipe.js";
6
6
 
7
7
  if (!global['crypto']) {
8
8
  global['crypto'] = new Crypto.Crypto();
9
9
  }
10
10
 
11
11
  describe('Pipe', function () {
12
+ describe('run different pipes', function () {
13
+ [
14
+ ['path:b | if:x:\\ ', {a:true}, ' '], // '\\ '.length ↦ 2
15
+ ['path:a | if:x:\\ ', {a:true}, 'x'],
16
+ ['nop', 'abcdefghijklmnop', 'abcdefghijklmnop'],
17
+
18
+ ].forEach(function (data) {
19
+
20
+ let a = data.shift()
21
+ let b = data.shift()
22
+ let c = data.shift()
23
+
24
+ it('Pipe.run(' + JSON.stringify(a) + ').run(' + JSON.stringify(b) + ') should return ' + JSON.stringify(c), function () {
25
+ let t = new Pipe(a);
26
+
27
+ const r = t.run(b);
28
+ expect(r).to.be.eql(c);
29
+ });
30
+ });
31
+
32
+
33
+ });
34
+
35
+
12
36
  describe('new Pipe should create new Instance', function () {
13
37
 
14
38
  it('should return Instance', function () {
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
 
3
- import {Transformer} from "../../../source/data/transformer.js";
3
+ import * as Crypto from "@peculiar/webcrypto";
4
4
  import {expect} from "chai"
5
+ import {Transformer} from "../../../source/data/transformer.js";
5
6
  import {initJSDOM} from "../../util/jsdom.js";
6
- import * as Crypto from "@peculiar/webcrypto";
7
7
 
8
8
 
9
9
  if (!global['crypto']) {
@@ -22,6 +22,31 @@ describe('Transformer', function () {
22
22
  describe('Transformer.run()', function () {
23
23
 
24
24
  [
25
+ ['??:a', null, 'a'],
26
+ ['??:a', undefined, 'a'],
27
+ ['??:a', 'true', 'true'],
28
+ ['??:a', false, false],
29
+ [' if:a: ', false, undefined], // without \\
30
+ [' if:a:\\ ', false, " "],
31
+ [' if:a:\\ ', true, "a"],
32
+ ['default:yes', null, 'yes'],
33
+ ['default:yes', undefined, 'yes'],
34
+ ['default:1:bool', undefined, true],
35
+ ['default:on:bool', undefined, true],
36
+ ['default:true:bool', undefined, true],
37
+ ['default:yes:bool', undefined, true],
38
+ ['default:undefined:bool', undefined, false],
39
+ ['default:false:bool', undefined, false],
40
+ ['default:1:int', undefined, 1],
41
+ ['default:1:string', undefined, '1'],
42
+ ['first-key', {a: 1, c: 3, b: 2}, 1],
43
+ ['last-key', {a: 1, c: 3, b: 2}, 3],
44
+ ['nth-last-key:0', {a: 1, c: 3, b: 2}, 3],
45
+ ['nth-last-key:1', {a: 1, c: 3, b: 2}, 2],
46
+ ['nth-last-key:2', {a: 1, c: 3, b: 2}, 1],
47
+ ['nth-key:2', {a: 1, b: 2, c: 3}, 3],
48
+ ['nth-key:0', {c: 3, a: 1, b: 2}, 1],
49
+ ['nth-key:2', {a: 1, c: 3, b: 2}, 3],
25
50
  ['prefix:Hello\\ ', 'test', "Hello test"],
26
51
  ['tojson', {a: 4}, "{\"a\":4}"],
27
52
  ['prefix:a\\\\: ', 'test', "a\\test"],
@@ -55,7 +80,10 @@ describe('Transformer', function () {
55
80
  ['ucwords', 'cAr runs', "CAr Runs"],
56
81
  ['tointeger', '6', 6],
57
82
  ['length', 'test', 4],
58
- ['base64', 'test', "dGVzdA=="],
83
+ ['to-base64', 'Hello World!', "SGVsbG8gV29ybGQh"],
84
+ ['from-base64', 'SGVsbG8gV29ybGQh', "Hello World!"],
85
+ ['to-base64', 'test', "dGVzdA=="],
86
+ ['from-base64', "dGVzdA==", 'test'],
59
87
  ['prefix:a', 'test', "atest"],
60
88
  ['suffix:a', 'test', "testa"],
61
89
  ['index:a', {a: 4}, 4],
@@ -80,13 +108,8 @@ describe('Transformer', function () {
80
108
  return a + b + c + d;
81
109
  });
82
110
 
83
- if (typeof c === 'object') {
84
- b = JSON.stringify(b);
85
- c = JSON.stringify(c);
86
- }
87
-
88
-
89
- expect(t.run(b)).to.be.equal(c);
111
+ const r = t.run(b);
112
+ expect(r).to.be.eql(c);
90
113
  });
91
114
  });
92
115
 
@@ -140,6 +163,14 @@ describe('Transformer', function () {
140
163
 
141
164
  });
142
165
 
166
+ describe('new Transformer().run("default:eyJiIjoxfQ==:object")', function () {
167
+ it('should return Object', function () {
168
+ let t = new Transformer('default:eyJiIjoxfQ==:object');
169
+ expect(t.run(undefined)).to.eql({b: 1});
170
+ });
171
+
172
+ });
173
+
143
174
 
144
175
  describe('new Transformer()', function () {
145
176
  it('should return instanceof Transformer', function () {
@@ -1,11 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ import chai from "chai"
3
4
  import {ATTRIBUTE_OPTIONS} from "../../../source/dom/constants.js";
4
5
  import {getDocument} from "../../../source/dom/util.js";
5
- import {ID} from "../../../source/types/id.js";
6
- import {initJSDOM} from "../../util/jsdom.js";
7
- import chai from "chai"
8
6
  import {chaiDom} from "../../util/chai-dom.js";
7
+ import {initJSDOM} from "../../util/jsdom.js";
9
8
 
10
9
 
11
10
  let expect = chai.expect;
@@ -77,10 +76,12 @@ describe('DOM', function () {
77
76
 
78
77
  describe('connect empty element', function () {
79
78
  it('document should contain monster-customcontrol', function () {
79
+
80
80
  let d = document.createElement('monster-customcontrol');
81
81
  document.getElementById('test1').appendChild(d);
82
82
  expect(document.getElementsByTagName('monster-customcontrol').length).is.equal(1);
83
- expect(document.getElementById('test1')).contain.html('<monster-customcontrol data-monster-objectlink="Symbol(monsterUpdater)"></monster-customcontrol>');
83
+ // no data-monster-objectlink="Symbol(monsterUpdater)" because it has nothing to update
84
+ expect(document.getElementById('test1')).contain.html('<monster-customcontrol></monster-customcontrol>');
84
85
  });
85
86
  });
86
87
 
@@ -97,7 +98,7 @@ describe('DOM', function () {
97
98
 
98
99
 
99
100
  })
100
-
101
+
101
102
  describe('Test ElementInternals', function () {
102
103
 
103
104
  let form;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  import chai from "chai"
4
- import {PROPERTY_KEY_INTERNALDATA} from "../../../source/constants.js";
4
+ import {internalSymbol} from "../../../source/constants.js";
5
5
  import {ATTRIBUTE_OPTIONS} from "../../../source/dom/constants.js";
6
6
  import {getDocument} from "../../../source/dom/util.js";
7
7
  import {chaiDom} from "../../util/chai-dom.js";
@@ -16,13 +16,12 @@ let html1 = `
16
16
  </div>
17
17
  `;
18
18
 
19
- const internalDataSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
19
+
20
20
 
21
21
  describe('DOM', function () {
22
22
 
23
23
  let CustomElement, registerCustomElement, TestComponent, document, TestComponent2;
24
24
 
25
-
26
25
  describe('CustomElement()', function () {
27
26
 
28
27
 
@@ -98,7 +97,8 @@ describe('DOM', function () {
98
97
  let d = document.createElement('monster-testclass');
99
98
  document.getElementById('test1').appendChild(d);
100
99
  expect(document.getElementsByTagName('monster-testclass').length).is.equal(1);
101
- expect(document.getElementById('test1')).contain.html('<monster-testclass data-monster-objectlink="Symbol(monsterUpdater)"></monster-testclass>');
100
+ // no data-monster-objectlink="Symbol(monsterUpdater)" because it has nothing to update
101
+ expect(document.getElementById('test1')).contain.html('<monster-testclass></monster-testclass>');
102
102
  });
103
103
  });
104
104
 
@@ -108,16 +108,17 @@ describe('DOM', function () {
108
108
  document.getElementById('test1').appendChild(d);
109
109
 
110
110
  // insert DOM run in extra process via setTimeout!
111
- // setTimeout(function () {
112
- try {
113
- expect(document.getElementsByTagName('monster-testclass2').length).is.equal(1);
114
- expect(document.getElementsByTagName('monster-testclass2').item(0).shadowRoot.innerHTML).is.equal('<h1></h1><article><p>test</p><div id="container"></div></article>');
115
- expect(document.getElementById('test1')).contain.html('<monster-testclass2 data-monster-objectlink="Symbol(monsterUpdater)"></monster-testclass2>');
116
- } catch (e) {
117
- done(e);
118
- }
119
- done();
120
- //}, 100);
111
+ setTimeout(function () {
112
+ try {
113
+ expect(document.getElementsByTagName('monster-testclass2').length).is.equal(1);
114
+ expect(document.getElementsByTagName('monster-testclass2').item(0).shadowRoot.innerHTML).is.equal('<h1></h1><article><p>test</p><div id="container"></div></article>');
115
+ expect(document.getElementById('test1')).contain.html('<monster-testclass2 data-monster-objectlink="Symbol(monsterUpdater)"></monster-testclass2>');
116
+ return done();
117
+ } catch (e) {
118
+ done(e);
119
+ }
120
+
121
+ }, 10);
121
122
 
122
123
  });
123
124
  });
@@ -127,20 +128,20 @@ describe('DOM', function () {
127
128
  it('delegatesFocus should change from true to false', function () {
128
129
  let element = document.createElement('monster-testclass')
129
130
 
130
- const o = element[internalDataSymbol].realSubject;
131
- expect(Object.is(element[internalDataSymbol].realSubject, o)).to.be.true;
131
+ const o = element[internalSymbol].realSubject;
132
+ expect(Object.is(element[internalSymbol].realSubject, o)).to.be.true;
132
133
 
133
- expect(element[internalDataSymbol].realSubject.options.delegatesFocus).to.be.true;
134
- expect(element[internalDataSymbol].subject.options.delegatesFocus).to.be.true;
134
+ expect(element[internalSymbol].realSubject.options.delegatesFocus).to.be.true;
135
+ expect(element[internalSymbol].subject.options.delegatesFocus).to.be.true;
135
136
  expect(element.getOption('delegatesFocus')).to.be.true;
136
- expect(Object.is(element[internalDataSymbol].realSubject, o)).to.be.true;
137
+ expect(Object.is(element[internalSymbol].realSubject, o)).to.be.true;
137
138
 
138
139
  element.setAttribute(ATTRIBUTE_OPTIONS, JSON.stringify({delegatesFocus: false}));
139
- expect(Object.is(element[internalDataSymbol].realSubject, o)).to.be.true;
140
+ expect(Object.is(element[internalSymbol].realSubject, o)).to.be.true;
140
141
 
141
142
  expect(element.getOption('delegatesFocus')).to.be.false;
142
- expect(element[internalDataSymbol].realSubject.options.delegatesFocus).to.be.false;
143
- expect(Object.is(element[internalDataSymbol].realSubject, o)).to.be.true;
143
+ expect(element[internalSymbol].realSubject.options.delegatesFocus).to.be.false;
144
+ expect(Object.is(element[internalSymbol].realSubject, o)).to.be.true;
144
145
 
145
146
  })
146
147
 
@@ -238,8 +239,6 @@ describe('DOM', function () {
238
239
 
239
240
  let n1 = document.createElement('p');
240
241
 
241
- console.log(document.body.innerHTML)
242
-
243
242
  expect(d.hasNode(n1)).to.be.false;
244
243
  expect(d.hasNode(t)).to.be.true;
245
244
  expect(d.hasNode(p)).to.be.true;
@@ -259,13 +258,13 @@ describe('DOM', function () {
259
258
  let t = document.createTextNode('test');
260
259
  p.appendChild(p1);
261
260
  p.appendChild(t);
262
-
261
+
263
262
 
264
263
  let div = document.getElementById('test1');
265
264
  div.append(d);
266
265
 
267
266
  let a = d.shadowRoot.getElementById('container');
268
-
267
+
269
268
  d.shadowRoot.getElementById('container').appendChild(p);
270
269
 
271
270
  let n1 = document.createElement('p');