@schukai/monster 1.22.0 → 1.26.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. package/CHANGELOG +56 -0
  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 +2 -2
  14. package/dist/modules/data/buildtree.js +2 -0
  15. package/dist/modules/data/datasource/namespace.js +1 -1
  16. package/dist/modules/data/datasource/restapi/writeerror.js +2 -0
  17. package/dist/modules/data/datasource/restapi.js +2 -2
  18. package/dist/modules/data/datasource/storage/localstorage.js +2 -2
  19. package/dist/modules/data/datasource/storage/namespace.js +1 -1
  20. package/dist/modules/data/datasource/storage/sessionstorage.js +2 -2
  21. package/dist/modules/data/datasource/storage.js +2 -2
  22. package/dist/modules/data/datasource.js +2 -2
  23. package/dist/modules/data/diff.js +2 -2
  24. package/dist/modules/data/extend.js +1 -1
  25. package/dist/modules/data/namespace.js +1 -1
  26. package/dist/modules/data/pathfinder.js +2 -2
  27. package/dist/modules/data/pipe.js +1 -1
  28. package/dist/modules/data/transformer.js +2 -2
  29. package/dist/modules/dom/assembler.js +1 -1
  30. package/dist/modules/dom/attributes.js +1 -1
  31. package/dist/modules/dom/constants.js +2 -2
  32. package/dist/modules/dom/customcontrol.js +2 -2
  33. package/dist/modules/dom/customelement.js +2 -2
  34. package/dist/modules/dom/events.js +1 -1
  35. package/dist/modules/dom/focusmanager.js +2 -0
  36. package/dist/modules/dom/locale.js +1 -1
  37. package/dist/modules/dom/namespace.js +1 -1
  38. package/dist/modules/dom/resource/data.js +2 -0
  39. package/dist/modules/dom/resource/link/stylesheet.js +2 -0
  40. package/dist/modules/dom/resource/link.js +2 -0
  41. package/dist/modules/dom/resource/script.js +2 -0
  42. package/dist/modules/dom/resource.js +2 -0
  43. package/dist/modules/dom/resourcemanager.js +2 -0
  44. package/dist/modules/dom/template.js +1 -1
  45. package/dist/modules/dom/theme.js +1 -1
  46. package/dist/modules/dom/updater.js +2 -2
  47. package/dist/modules/dom/util.js +1 -1
  48. package/dist/modules/dom/worker/factory.js +2 -0
  49. package/dist/modules/i18n/formatter.js +2 -0
  50. package/dist/modules/i18n/locale.js +1 -1
  51. package/dist/modules/i18n/namespace.js +1 -1
  52. package/dist/modules/i18n/provider.js +1 -1
  53. package/dist/modules/i18n/providers/fetch.js +2 -2
  54. package/dist/modules/i18n/providers/namespace.js +1 -1
  55. package/dist/modules/i18n/translations.js +1 -1
  56. package/dist/modules/logging/handler/console.js +1 -1
  57. package/dist/modules/logging/handler/namespace.js +1 -1
  58. package/dist/modules/logging/handler.js +1 -1
  59. package/dist/modules/logging/logentry.js +1 -1
  60. package/dist/modules/logging/logger.js +1 -1
  61. package/dist/modules/logging/namespace.js +1 -1
  62. package/dist/modules/math/namespace.js +1 -1
  63. package/dist/modules/math/random.js +2 -2
  64. package/dist/modules/monster.js +1 -1
  65. package/dist/modules/namespace.js +1 -1
  66. package/dist/modules/text/formatter.js +2 -2
  67. package/dist/modules/text/namespace.js +1 -1
  68. package/dist/modules/types/base.js +1 -1
  69. package/dist/modules/types/basewithoptions.js +2 -2
  70. package/dist/modules/types/binary.js +1 -1
  71. package/dist/modules/types/dataurl.js +1 -1
  72. package/dist/modules/types/global.js +1 -1
  73. package/dist/modules/types/id.js +1 -1
  74. package/dist/modules/types/is.js +2 -2
  75. package/dist/modules/types/mediatype.js +1 -1
  76. package/dist/modules/types/namespace.js +1 -1
  77. package/dist/modules/types/node.js +2 -0
  78. package/dist/modules/types/nodelist.js +2 -0
  79. package/dist/modules/types/noderecursiveiterator.js +2 -0
  80. package/dist/modules/types/observer.js +1 -1
  81. package/dist/modules/types/observerlist.js +2 -2
  82. package/dist/modules/types/proxyobserver.js +2 -2
  83. package/dist/modules/types/queue.js +1 -1
  84. package/dist/modules/types/randomid.js +1 -1
  85. package/dist/modules/types/regex.js +2 -0
  86. package/dist/modules/types/stack.js +1 -1
  87. package/dist/modules/types/tokenlist.js +2 -2
  88. package/dist/modules/types/typeof.js +1 -1
  89. package/dist/modules/types/uniquequeue.js +1 -1
  90. package/dist/modules/types/uuid.js +2 -0
  91. package/dist/modules/types/validate.js +1 -1
  92. package/dist/modules/types/version.js +2 -2
  93. package/dist/modules/util/clone.js +2 -2
  94. package/dist/modules/util/comparator.js +2 -2
  95. package/dist/modules/util/freeze.js +1 -1
  96. package/dist/modules/util/namespace.js +1 -1
  97. package/dist/modules/util/processing.js +2 -2
  98. package/dist/modules/util/trimspaces.js +2 -0
  99. package/dist/monster.dev.js +1838 -792
  100. package/dist/monster.dev.js.map +1 -1
  101. package/dist/monster.js +2 -2
  102. package/package.json +13 -2
  103. package/source/constants.js +16 -7
  104. package/source/constraints/abstract.js +5 -0
  105. package/source/constraints/abstractoperator.js +5 -0
  106. package/source/constraints/andoperator.js +10 -5
  107. package/source/constraints/invalid.js +8 -3
  108. package/source/constraints/isarray.js +9 -4
  109. package/source/constraints/isobject.js +8 -3
  110. package/source/constraints/oroperator.js +10 -5
  111. package/source/constraints/valid.js +8 -3
  112. package/source/data/buildmap.js +27 -11
  113. package/source/data/buildtree.js +95 -0
  114. package/source/data/datasource/restapi/writeerror.js +49 -0
  115. package/source/data/datasource/restapi.js +95 -11
  116. package/source/data/datasource/storage/localstorage.js +15 -8
  117. package/source/data/datasource/storage/sessionstorage.js +16 -12
  118. package/source/data/datasource/storage.js +16 -7
  119. package/source/data/datasource.js +60 -16
  120. package/source/data/diff.js +8 -8
  121. package/source/data/extend.js +5 -5
  122. package/source/data/pathfinder.js +12 -6
  123. package/source/data/pipe.js +6 -5
  124. package/source/data/transformer.js +131 -24
  125. package/source/dom/assembler.js +2 -2
  126. package/source/dom/attributes.js +24 -24
  127. package/source/dom/constants.js +305 -12
  128. package/source/dom/customcontrol.js +40 -19
  129. package/source/dom/customelement.js +182 -102
  130. package/source/dom/events.js +6 -6
  131. package/source/dom/focusmanager.js +250 -0
  132. package/source/dom/locale.js +10 -5
  133. package/source/dom/resource/data.js +170 -0
  134. package/source/dom/resource/link/stylesheet.js +54 -0
  135. package/source/dom/resource/link.js +125 -0
  136. package/source/dom/resource/script.js +112 -0
  137. package/source/dom/resource.js +268 -0
  138. package/source/dom/resourcemanager.js +214 -0
  139. package/source/dom/template.js +40 -10
  140. package/source/dom/theme.js +3 -3
  141. package/source/dom/updater.js +115 -39
  142. package/source/dom/util.js +6 -6
  143. package/source/dom/worker/factory.js +134 -0
  144. package/source/i18n/formatter.js +140 -0
  145. package/source/i18n/locale.js +10 -8
  146. package/source/i18n/provider.js +4 -4
  147. package/source/i18n/providers/fetch.js +24 -14
  148. package/source/i18n/translations.js +20 -10
  149. package/source/logging/handler/console.js +2 -2
  150. package/source/logging/handler.js +2 -2
  151. package/source/logging/logentry.js +2 -2
  152. package/source/logging/logger.js +4 -4
  153. package/source/math/random.js +11 -5
  154. package/source/namespace.js +1 -1
  155. package/source/text/formatter.js +244 -27
  156. package/source/types/base.js +4 -4
  157. package/source/types/basewithoptions.js +10 -15
  158. package/source/types/binary.js +8 -8
  159. package/source/types/dataurl.js +6 -6
  160. package/source/types/global.js +9 -7
  161. package/source/types/id.js +6 -3
  162. package/source/types/is.js +103 -85
  163. package/source/types/mediatype.js +4 -4
  164. package/source/types/node.js +179 -0
  165. package/source/types/nodelist.js +125 -0
  166. package/source/types/noderecursiveiterator.js +126 -0
  167. package/source/types/observer.js +3 -3
  168. package/source/types/observerlist.js +3 -3
  169. package/source/types/proxyobserver.js +24 -7
  170. package/source/types/queue.js +6 -6
  171. package/source/types/randomid.js +2 -2
  172. package/source/types/regex.js +49 -0
  173. package/source/types/stack.js +2 -2
  174. package/source/types/tokenlist.js +8 -9
  175. package/source/types/typeof.js +3 -3
  176. package/source/types/uniquequeue.js +4 -4
  177. package/source/types/uuid.js +102 -0
  178. package/source/types/validate.js +20 -20
  179. package/source/types/version.js +6 -6
  180. package/source/util/clone.js +5 -6
  181. package/source/util/comparator.js +5 -5
  182. package/source/util/freeze.js +5 -5
  183. package/source/util/processing.js +33 -36
  184. package/source/util/trimspaces.js +85 -0
  185. package/test/cases/data/buildtree.js +149 -0
  186. package/test/cases/data/datasource/restapi.js +1 -1
  187. package/test/cases/data/datasource.js +4 -4
  188. package/test/cases/data/diff.js +4 -4
  189. package/test/cases/data/pathfinder.js +18 -9
  190. package/test/cases/data/pipe.js +26 -2
  191. package/test/cases/data/transformer.js +41 -10
  192. package/test/cases/dom/attributes.js +18 -14
  193. package/test/cases/dom/customcontrol.js +6 -5
  194. package/test/cases/dom/customelement.js +25 -26
  195. package/test/cases/dom/focusmanager.js +111 -0
  196. package/test/cases/dom/locale.js +1 -4
  197. package/test/cases/dom/resource/data.js +129 -0
  198. package/test/cases/dom/resource/link/stylesheet.js +101 -0
  199. package/test/cases/dom/resource/link.js +101 -0
  200. package/test/cases/dom/resource/script.js +115 -0
  201. package/test/cases/dom/resourcemanager.js +118 -0
  202. package/test/cases/dom/updater.js +42 -19
  203. package/test/cases/dom/worker/factory.js +63 -0
  204. package/test/cases/i18n/formatter.js +66 -0
  205. package/test/cases/monster.js +1 -1
  206. package/test/cases/text/formatter.js +71 -8
  207. package/test/cases/types/node.js +196 -0
  208. package/test/cases/types/nodelist.js +64 -0
  209. package/test/cases/types/noderecursiveiterator.js +54 -0
  210. package/test/cases/types/proxyobserver.js +55 -11
  211. package/test/cases/types/regex.js +32 -0
  212. package/test/cases/types/uuid.js +42 -0
  213. package/test/cases/util/freeze.js +30 -4
  214. package/test/cases/util/trimspaces.js +24 -0
  215. package/test/util/cleanupdom.js +48 -0
  216. package/test/util/jsdom.js +22 -9
  217. package/test/web/import.js +15 -0
  218. package/test/web/monster-dev.html +3 -3
  219. package/test/web/monster.html +2 -2
  220. package/test/web/test.html +3 -3
  221. package/test/web/tests.js +7 -7
@@ -0,0 +1,85 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @author schukai GmbH
5
+ */
6
+
7
+ import {assignToNamespace, Monster} from "../namespace.js";
8
+ import {ID} from "../types/id.js";
9
+ import {isObject} from "../types/is.js";
10
+ import {validateString} from "../types/validate.js";
11
+
12
+ /**
13
+ * This special trim function allows to trim spaces that have been protected by a special escape character.
14
+ *
15
+ * You can call the method via the monster namespace `Monster.Util.trimSpaces()`.
16
+ *
17
+ * ```
18
+ * <script type="module">
19
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
20
+ * Monster.Util.trimSpaces(" hello ")
21
+ * </script>
22
+ * ```
23
+ *
24
+ * Alternatively, you can also integrate this function individually.
25
+ *
26
+ * ```
27
+ * <script type="module">
28
+ * import {trimSpaces} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/util/trimspaces.js';
29
+ * trimSpaces(' hello \\ ')
30
+ * </script>
31
+ * ```
32
+ *
33
+ * Hint: One stroke is escaped by the javascript interpreter, the second stroke escapes the stroke.
34
+ *
35
+ * ```text
36
+ * a\ b ↦ a b
37
+ * a\\ b ↦ a\ b
38
+ * ```
39
+ *
40
+ * @since 1.24.0
41
+ * @memberOf Monster.Util
42
+ * @copyright schukai GmbH
43
+ * @param {string} value
44
+ * @return {string}
45
+ * @throws {TypeError} value is not a string
46
+ */
47
+ function trimSpaces(value) {
48
+
49
+ validateString(value);
50
+
51
+ let placeholder = new Map;
52
+ const regex = /((?<pattern>\\(?<char>.)){1})/mig;
53
+
54
+ // The separator for args must be escaped
55
+ // undefined string which should not occur normally and is also not a regex
56
+ let result = value.matchAll(regex)
57
+
58
+ for (let m of result) {
59
+ let g = m?.['groups'];
60
+ if (!isObject(g)) {
61
+ continue;
62
+ }
63
+
64
+ let p = g?.['pattern'];
65
+ let c = g?.['char'];
66
+
67
+ if (p && c) {
68
+ let r = '__' + new ID().toString() + '__';
69
+ placeholder.set(r, c);
70
+ value = value.replace(p, r);
71
+ }
72
+
73
+ }
74
+
75
+ value = value.trim();
76
+ placeholder.forEach((v, k) => {
77
+ value = value.replace(k, '\\' + v)
78
+ })
79
+
80
+ return value;
81
+
82
+ }
83
+
84
+ assignToNamespace('Monster.Util', trimSpaces);
85
+ export {Monster, trimSpaces}
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+
3
+ import {expect} from "chai"
4
+ import {buildTree} from "../../../source/data/buildtree.js";
5
+ import {NodeList} from "../../../source/types/nodelist.js";
6
+ import {NodeRecursiveIterator} from "../../../source/types/noderecursiveiterator.js";
7
+
8
+
9
+ describe('buildTree', function () {
10
+
11
+ describe('example', function () {
12
+
13
+ it('should run example', function () {
14
+
15
+ const objects = {
16
+ dataset: {
17
+ "1": {
18
+ id: "1",
19
+ name: "vehicle",
20
+ parent: null
21
+
22
+ },
23
+ "2": {
24
+ id: "2",
25
+ name: "car",
26
+ parent: "1"
27
+ },
28
+ "3": {
29
+ id: "3",
30
+ name: "truck",
31
+ parent: "1"
32
+ },
33
+ "4": {
34
+ id: "4",
35
+ name: "motorcycle",
36
+ parent: "1"
37
+ },
38
+ "5": {
39
+ id: "5",
40
+ name: "SUV",
41
+ parent: "2"
42
+ },
43
+ "6": {
44
+ id: "6",
45
+ name: "sports car",
46
+ parent: "2"
47
+ }
48
+ }
49
+ }
50
+
51
+ const nodes = buildTree(objects, 'dataset.*', 'id', 'parent');
52
+
53
+ let result = ""
54
+ nodes.forEach(node => {
55
+ new NodeRecursiveIterator(node).forEach(n => {
56
+ result +="".padStart(n.level * 2, '.') + (n.value.name);
57
+ });
58
+
59
+ });
60
+
61
+ expect(result).to.be.equal('vehicle..car....SUV....sports car..truck..motorcycle');
62
+ expect(nodes).to.be.instanceOf(NodeList);
63
+ expect(nodes.length).to.equal(1);
64
+ expect(nodes.length).to.equal(1);
65
+
66
+
67
+ })
68
+ })
69
+
70
+ describe('buildTree()', function () {
71
+
72
+ let obj1 = {
73
+ dataset: {
74
+ "1": {
75
+ id: "1",
76
+ name: "Test 1",
77
+ address: "Here 1",
78
+ parent: null
79
+
80
+ },
81
+ "2": {
82
+ id: "2",
83
+ name: "Test 2",
84
+ address: "Here 2",
85
+ parent: "1"
86
+ },
87
+ "3": {
88
+ id: "3",
89
+ name: "Test 3",
90
+ address: "Here 3",
91
+ parent: "2"
92
+ },
93
+ "4": {
94
+ id: "4",
95
+ name: "Test 4",
96
+ address: "Here 4",
97
+ parent: "2"
98
+ },
99
+ "5": {
100
+ id: "5",
101
+ name: "Test 5",
102
+ address: "Here 5",
103
+ parent: "1"
104
+ },
105
+ "6": {
106
+ id: "6",
107
+ name: "Test 6",
108
+ address: "Here 6",
109
+ parent: "4"
110
+ }
111
+ }
112
+ };
113
+
114
+ it('should return Node Instance.', function () {
115
+ expect(buildTree({}, '')).to.be.instanceOf(NodeList);
116
+ });
117
+
118
+ [
119
+ [obj1, 'dataset.*', '1,2,3,4,6,5'],
120
+ [obj1, 'x', ''],
121
+ [obj1, 'dataset.*', '1,2,3,4,6,5'],
122
+ ].forEach(function (data) {
123
+
124
+ let a = data.shift()
125
+ let b = data.shift()
126
+ let c = data.shift()
127
+
128
+ it('buildTree(' + JSON.stringify(a) + ',' + JSON.stringify(b) + ') should return ' + JSON.stringify(c) + ' ', function () {
129
+ let nodelist = buildTree(a, b, 'id', 'parent');
130
+
131
+ let result = [];
132
+
133
+ const firstNode = nodelist.toArray().shift();
134
+
135
+ if (firstNode) {
136
+ for (const node of new NodeRecursiveIterator(firstNode)) {
137
+ result.push(node.value.id);
138
+ }
139
+ }
140
+
141
+ expect(result.join(',')).to.be.equal(c);
142
+ });
143
+ });
144
+
145
+
146
+ });
147
+
148
+
149
+ });
@@ -7,7 +7,7 @@ import {validateObject} from "../../../../source/types/validate.js";
7
7
 
8
8
  describe('RestAPI', function () {
9
9
 
10
- let fetchReference;
10
+ let fetchReference;
11
11
  let returnStatus;
12
12
 
13
13
  afterEach(() => {
@@ -44,13 +44,13 @@ describe('Datasource', function () {
44
44
  describe('get/set', function () {
45
45
  const datasource = new Datasource();
46
46
  it('get should return undefined', function () {
47
- expect( datasource.get()).to.be.undefined;
47
+ expect( datasource.get()).to.be.eql({});
48
48
  });
49
49
 
50
50
  it('write should throw exeption', function () {
51
- expect( datasource.get()).to.be.undefined;
52
- expect( datasource.set('myvalue')).to.be.instanceof(Datasource);
53
- expect( datasource.get()).to.be.equal('myvalue');
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
54
  });
55
55
 
56
56
 
@@ -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 () {
@@ -4,23 +4,28 @@ import {expect} from "chai"
4
4
 
5
5
  import {
6
6
  addAttributeToken,
7
- toggleAttributeToken,
8
- containsAttributeToken,
9
- replaceAttributeToken,
7
+ addToObjectLink,
10
8
  clearAttributeTokens,
11
- removeAttributeToken,
9
+ containsAttributeToken,
10
+ findClosestByAttribute,
11
+ findClosestObjectLink,
12
+ getLinkedObjects,
12
13
  hasObjectLink,
13
- addToObjectLink,
14
+ removeAttributeToken,
14
15
  removeObjectLink,
15
- getLinkedObjects,
16
- findClosestObjectLink,
17
- findClosestByAttribute
16
+ replaceAttributeToken,
17
+ toggleAttributeToken
18
18
  } from "../../../source/dom/attributes.js";
19
19
 
20
20
  import {initJSDOM} from "../../util/jsdom.js";
21
21
 
22
- let html1 = `<div id="test1"></div>`;
23
- let html2 = `<div id="test1">
22
+ let html1, html2, html3;
23
+
24
+ describe('Attributes', function () {
25
+ before(function (done) {
26
+
27
+ html1 = `<div id="test1"></div>`;
28
+ html2 = `<div id="test1">
24
29
  <div id="sub1">
25
30
  <div id="sub2">
26
31
  <div id="sub3">
@@ -32,7 +37,7 @@ let html2 = `<div id="test1">
32
37
  </div>
33
38
  </div>
34
39
  `;
35
- let html3 = `<div data-monster-role="test1">
40
+ html3 = `<div data-monster-role="test1">
36
41
  <div data-monster-role="sub1" id="a1">
37
42
  <div data-monster-role="sub2" id="a2">
38
43
  <div data-monster-role="sub3" id="a3">
@@ -45,11 +50,10 @@ let html3 = `<div data-monster-role="test1">
45
50
  </div>
46
51
  `;
47
52
 
48
- describe('Attributes', function () {
49
- before(function (done) {
53
+
50
54
  initJSDOM().then(() => {
51
55
  done()
52
- });
56
+ }).catch(e => done(e));
53
57
  });
54
58
 
55
59
  describe('ObjectLink', 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;