@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
@@ -1,13 +1,12 @@
1
1
  'use strict';
2
2
 
3
+ import chai from "chai"
3
4
  import {Updater} from "../../../source/dom/updater.js";
5
+ import {ID} from "../../../source/types/id.js";
4
6
  import {Observer} from "../../../source/types/observer.js";
5
7
  import {ProxyObserver} from "../../../source/types/proxyobserver.js";
6
-
7
-
8
- import chai from "chai"
9
- import {initJSDOM} from "../../util/jsdom.js";
10
8
  import {chaiDom} from "../../util/chai-dom.js";
9
+ import {initJSDOM} from "../../util/jsdom.js";
11
10
 
12
11
  let expect = chai.expect;
13
12
 
@@ -57,7 +56,7 @@ let html2 = `
57
56
  <div id="test1">
58
57
  <div data-monster-replace="path:text | tolower"> </div>
59
58
  <div data-monster-replace="path:text | call:myformatter"> </div>
60
- <div data-monster-replace="static:hello"></div>
59
+ <div data-monster-replace="static:hello\\ "></div>
61
60
  </div>
62
61
  `;
63
62
 
@@ -283,10 +282,10 @@ describe('DOM', function () {
283
282
  if (e === undefined && expected.length === 0) done(new Error('to many calls'));
284
283
 
285
284
  if (this.getSubject()['state'] !== e) done(new Error(this.getSubject()['state'] + ' should ' + e));
286
- if (expected.length === 0) {
285
+ if (expected.length === 0) {
287
286
  done();
288
287
  } else {
289
-
288
+
290
289
  setTimeout(() => {
291
290
  form1.querySelector('[name=checkbox]').click();
292
291
  }, 10)
@@ -501,21 +500,22 @@ describe('DOM', function () {
501
500
  return a + 'yes!'
502
501
  })
503
502
 
504
- d.run().then(() => {
503
+ setTimeout(() => {
504
+ d.run().then(() => {
505
505
 
506
- expect(typeof d).is.equal('object');
507
- expect(element).contain.html('<div data-monster-replace="path:text | tolower">hallo</div>');
508
- expect(element).contain.html('<div data-monster-replace="path:text | call:myformatter">HALLOyes!</div>');
509
- expect(element).contain.html('<div data-monster-replace="static:hello">hello</div>');
510
-
511
- done();
512
- }).catch(
513
- e => {
514
- done(new Error(e))
515
- })
506
+ expect(typeof d).is.equal('object');
507
+ expect(element).contain.html('<div data-monster-replace="path:text | tolower">hallo</div>');
508
+ expect(element).contain.html('<div data-monster-replace="path:text | call:myformatter">HALLOyes!</div>');
509
+ expect(element).contain.html('<div data-monster-replace="static:hello\\ ">hello </div>');
516
510
 
511
+ return done();
512
+ }).catch(
513
+ e => {
514
+ done(new Error(e))
515
+ })
516
+ }, 100)
517
517
 
518
- });
518
+ });
519
519
  });
520
520
  });
521
521
 
@@ -638,4 +638,27 @@ describe('DOM', function () {
638
638
  });
639
639
  });
640
640
 
641
+
642
+ describe('Get Attribute Pipe', function () {
643
+ let id, mocks;
644
+ beforeEach(() => {
645
+ mocks = document.getElementById('mocks');
646
+ id = new ID('monster');
647
+ mocks.innerHTML = ` <div id="` + id + `"
648
+ data-monster-replace="path:a | if:value:\\ "></div>`
649
+ })
650
+
651
+ afterEach(() => {
652
+ mocks.innerHTML = "";
653
+ })
654
+
655
+ it('should include space', function () {
656
+ const div = document.getElementById(id.toString())
657
+
658
+ const pipe = div.getAttribute('data-monster-replace');
659
+ expect(pipe.length).to.be.equal(20);
660
+
661
+ });
662
+ });
663
+
641
664
  });
@@ -0,0 +1,63 @@
1
+ import {expect} from "chai"
2
+
3
+ import {Factory} from "../../../../source/dom/worker/factory.js";
4
+ import {getGlobal} from "../../../../source/types/global.js";
5
+ import {initJSDOM, isNode} from "../../../util/jsdom.js";
6
+
7
+ const global = getGlobal();
8
+
9
+ describe('Worker', function () {
10
+
11
+ before(function (done) {
12
+
13
+ if (isNode()) {
14
+ Object.defineProperty(global['URL'], 'createObjectURL', {
15
+ writable: true,
16
+ value: () => {
17
+ return "/example.js"
18
+ }
19
+ })
20
+
21
+ global['Worker'] = class {
22
+ terminate() {
23
+
24
+ }
25
+
26
+ onerror() {
27
+
28
+ }
29
+
30
+ onmessage() {
31
+
32
+ }
33
+ }
34
+
35
+ let a = typeof global['Worker'];
36
+ let a1 = typeof Worker;
37
+
38
+ }
39
+
40
+ const jsdom = initJSDOM().then(() => {
41
+ done();
42
+ });
43
+
44
+
45
+ })
46
+
47
+ describe('Factory', function () {
48
+
49
+ it('create worker', function () {
50
+
51
+ const factory = new Factory();
52
+ const worker = factory.createFromScript('console.log("hello world");')
53
+ expect(worker).is.instanceof(Worker);
54
+
55
+ expect(factory.terminate(worker)).is.instanceof(Factory)
56
+
57
+
58
+ });
59
+
60
+ });
61
+
62
+
63
+ });
@@ -9,7 +9,7 @@ describe('Monster', function () {
9
9
  let monsterVersion
10
10
 
11
11
  /**#@+ dont touch, replaced by make with package.json version */
12
- monsterVersion = new Version('1.21.1')
12
+ monsterVersion = new Version('1.25.0')
13
13
  /**#@-*/
14
14
 
15
15
  let m = Monster.getVersion();
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  import {expect} from "chai"
4
2
  import {Formatter} from "../../../source/text/formatter.js";
5
3
 
@@ -57,10 +55,9 @@ describe('Formatter', function () {
57
55
  it('format ' + a + ' with marker ' + b + ' and ' + c + ' should return ' + b, function () {
58
56
 
59
57
  expect(
60
- new Formatter({
61
- a: "test"
62
- }).setMarker(b,c).format(a)
63
-
58
+ new Formatter({
59
+ a: "test"
60
+ }).setMarker(b, c).format(a)
64
61
  ).to.equal(d)
65
62
  });
66
63
  });
@@ -108,6 +105,41 @@ describe('Formatter', function () {
108
105
 
109
106
  });
110
107
 
108
+ describe('Marker in marker', function () {
109
+
110
+ let text = '${mykey${subkey}}';
111
+ let expected = '1';
112
+
113
+ it('format ' + text + ' should '+expected, function () {
114
+
115
+ let obj = {
116
+ mykey2: "1",
117
+ subkey: "2"
118
+ };
119
+
120
+ expect(new Formatter(obj).format(text)).is.equal(expected)
121
+
122
+ });
123
+
124
+
125
+ });
126
+
127
+ describe('Marker in marker with parameter', function () {
128
+
129
+ let text = '${mykey::mykey=${subkey}}';
130
+ let expected = '2';
131
+
132
+ it('format ' + text + ' should '+expected, function () {
133
+
134
+ let obj = {
135
+ subkey: "2"
136
+ };
137
+
138
+ expect(new Formatter(obj).format(text)).is.equal(expected)
139
+
140
+ });
141
+ });
142
+
111
143
  describe('exceptions', function () {
112
144
 
113
145
  [
@@ -1,23 +1,65 @@
1
1
  import {expect} from "chai"
2
+ import {extend} from "../../../source/data/extend.js";
3
+ import {isObject} from "../../../source/types/is.js";
4
+ import {Observer} from "../../../source/types/observer.js";
2
5
 
3
6
  import {ProxyObserver} from "../../../source/types/proxyobserver.js";
4
- import {Observer} from "../../../source/types/observer.js";
5
- import {isObject} from "../../../source/types/is.js";
6
7
 
7
8
  describe('ProxyObserver', function () {
8
9
 
10
+ describe('create', function () {
11
+ it('should return instanceof ProxyObserver', function () {
12
+ let o = new ProxyObserver({});
13
+ extend(o.getSubject(), {a: 4});
14
+ expect(o.getRealSubject()).is.eql({a: 4});
15
+ });
16
+ });
17
+
18
+ describe('setSubject', function () {
19
+ it('should run observer', function (done) {
20
+ let o = new ProxyObserver({a: 1});
21
+ expect(o.getRealSubject()).is.eql({a: 1});
22
+ let counter = 0;
23
+ o.attachObserver(new Observer(function () {
24
+ if (isObject(this) && this instanceof ProxyObserver) {
25
+ counter++;
26
+ // only one change as notify runs later
27
+ if (counter === 1) {
28
+ done();
29
+ return;
30
+ }
31
+ done("called for error");
32
+ return;
33
+ }
34
+
35
+ done(new Error("this is not ProxyObserver"))
36
+ }))
37
+
38
+ o.getSubject().c = 4;
39
+ expect(o.getRealSubject()).is.eql({a: 1, c: 4});
40
+
41
+ o.setSubject({b: 2});
42
+ expect(o.getRealSubject()).is.eql({b: 2});
43
+
44
+ o.getSubject().d = 5;
45
+ expect(o.getRealSubject()).is.eql({b: 2, d: 5});
46
+
47
+
48
+ });
49
+ });
50
+
9
51
  describe('create', function () {
10
52
  it('should return instanceof ProxyObserver', function () {
11
53
  let o = new ProxyObserver({});
12
54
  expect(o).is.instanceOf(ProxyObserver);
13
55
  });
14
56
  });
15
-
57
+
16
58
  describe('proxy objects', function () {
17
59
  it('Proxy objects should not be recommitted', function () {
18
- let o = new ProxyObserver({a:{b:true}});
19
- o.getSubject().a.b=o.getSubject();
20
- o.getSubject().a.b.a.b=false;
60
+ let o = new ProxyObserver({a: {b: true}});
61
+ o.getSubject().a.b = o.getSubject();
62
+ o.getSubject().a.b.a.b = false;
21
63
  //expect(o.getSubject()===p.getSubject()).to.be.true;
22
64
  });
23
65
  });
@@ -67,7 +109,7 @@ describe('ProxyObserver', function () {
67
109
 
68
110
  it('check Reflect.set() with Subject', function () {
69
111
  let r;
70
-
112
+
71
113
  const obj = (new ProxyObserver({})).getSubject();
72
114
 
73
115
  [
@@ -75,14 +117,16 @@ describe('ProxyObserver', function () {
75
117
  undefined,
76
118
  "no"
77
119
  ].forEach(function (value) {
78
- expect(()=>{obj['data']=value}).to.not.throw();
120
+ expect(() => {
121
+ obj['data'] = value
122
+ }).to.not.throw();
79
123
  //r = Reflect.set(obj, 'data', value)
80
124
  //expect(r).to.be.true;
81
125
  })
82
-
83
-
126
+
127
+
84
128
  });
85
-
129
+
86
130
 
87
131
  [
88
132
  ['that', {that: 'checked1'}],
@@ -0,0 +1,42 @@
1
+ import * as Crypto from "@peculiar/webcrypto";
2
+ import {expect} from "chai"
3
+ import {UUID} from "../../../source/types/uuid.js";
4
+
5
+ if (!global['crypto']) {
6
+ global['crypto'] = new Crypto.Crypto();
7
+ }
8
+
9
+
10
+ describe('UUID', function () {
11
+
12
+ describe('.toString()', function () {
13
+ let uuid = new UUID()
14
+ let result = uuid.toString();
15
+
16
+ it('should return a string', function () {
17
+ expect(result).is.a('string')
18
+ expect(result.length).is.equal(36)
19
+ });
20
+
21
+ it('test format', function (done) {
22
+
23
+ const regexExp = /^[A-F\d]{8}-[A-F\d]{4}-4[A-F\d]{3}-[89AB][A-F\d]{3}-[A-F\d]{12}$/i;
24
+
25
+ for (let i = 0; i < 2000; i++) {
26
+ const u = new UUID().toString();
27
+ const r = regexExp.test(u);
28
+
29
+ if (r !== true) {
30
+ done('no uuid ' + u + ' => ' + r);
31
+ return;
32
+ }
33
+ }
34
+
35
+ done();
36
+
37
+ });
38
+
39
+ });
40
+
41
+ });
42
+
@@ -10,13 +10,39 @@ describe('deepFreeze', function () {
10
10
 
11
11
  let obj1 = {
12
12
  a: {
13
- b: {}
13
+ b: {
14
+ c:1
15
+ }
14
16
  }
15
17
  };
16
18
 
17
- expect(() => obj1.a.b.c = 1).to.not.throw(TypeError);
18
- const obj2 = deepFreeze(obj1);
19
- expect(() => obj2.a.b.c = 1).to.throw(TypeError);
19
+ let obj2 = {
20
+ a: {
21
+ b: {
22
+ c:2
23
+ }
24
+ }
25
+ };
26
+
27
+ expect(obj2).to.not.eql(obj1)
28
+ obj1.a.b.c = 2;
29
+ expect(obj2).to.eql(obj1);
30
+
31
+ const obj1Freezed = deepFreeze(obj1);
32
+
33
+ expect(obj2).to.eql(obj1Freezed);
34
+
35
+ try {
36
+ // https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
37
+ // no change to the object, exception depends on mode (strict ES 2015, etc)
38
+ obj1Freezed.a.b.c = 3
39
+ } catch (_) {
40
+
41
+ }
42
+
43
+ expect(obj2).to.eql(obj1Freezed);
44
+
45
+
20
46
  });
21
47
 
22
48
  });
@@ -0,0 +1,24 @@
1
+ import {expect} from "chai"
2
+ import {trimSpaces} from "../../../source/util/trimspaces.js";
3
+
4
+
5
+ describe('trimSpaces', function () {
6
+ [
7
+ // one stroke is escped by the javascript interpreter, the second stroke escapes the stroke
8
+ [' value ', 'value'],
9
+ [' value\\ ', 'value\\ '],
10
+ ['\\ value\\ ', '\\ value\\ '],
11
+ ['\ value\ ', 'value'],
12
+ [" value \ ", 'value'],
13
+
14
+ ].forEach(function (data) {
15
+
16
+ let a = data.shift()
17
+ let b = data.shift()
18
+
19
+ it('trimSpaces(' + JSON.stringify(a) + ') should return ' + JSON.stringify(b), function () {
20
+ expect(trimSpaces(a)).to.be.equal(b);
21
+ });
22
+ });
23
+ });
24
+
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+
4
+ let addedNodes, mutationobserver;
5
+
6
+ function init() {
7
+
8
+ addedNodes = [];
9
+ mutationobserver = new MutationObserver(function (mutations) {
10
+ mutations.forEach(function (mutation) {
11
+ if (mutation.type === 'childList' && mutation.removedNodes) {
12
+
13
+ mutation.addedNodes.forEach((n) => {
14
+ if (n instanceof HTMLElement) {
15
+ addedNodes.push(n);
16
+ }
17
+ })
18
+ }
19
+
20
+ });
21
+ });
22
+
23
+
24
+ }
25
+
26
+
27
+ /**
28
+ *
29
+ */
30
+ export function initMutationObserverForTesting() {
31
+
32
+ if (mutationobserver === undefined) {
33
+ init()
34
+ }
35
+
36
+ mutationobserver.observe(document.querySelector('head'), {childList: true});
37
+ }
38
+
39
+ /**
40
+ *
41
+ */
42
+ export function cleanupDOMFromTesting() {
43
+ mutationobserver.disconnect();
44
+
45
+ for (const n of addedNodes) {
46
+ n.remove();
47
+ }
48
+ }
@@ -1,29 +1,40 @@
1
1
  'use strict';
2
2
 
3
+ import {extend} from "../../source/data/extend.js";
3
4
  import {getGlobal} from "../../source/types/global.js";
4
5
 
6
+ export const isBrowser = new Function("try {return this===window;}catch(e){ return false;}");
7
+
8
+ export const isNode = new Function("try {return this===global;}catch(e){return false;}");
9
+
10
+
5
11
  /**
6
12
  * this helper function creates the dom stack in the node environment
7
13
  *
8
14
  * @return {Promise<unknown>|Promise<void>}
9
15
  */
10
- function initJSDOM() {
16
+ function initJSDOM(options) {
11
17
  if (typeof window === "object" && window['DOMParser']) return Promise.resolve();
18
+ // if(isBrowser()) return Promise.resolve();
12
19
 
13
20
  const g = getGlobal();
14
21
 
22
+ options = extend({}, {
23
+ pretendToBeVisual: true,
24
+ contentType: "text/html",
25
+ includeNodeLocations: true,
26
+ storageQuota: 10000000,
27
+ runScripts: "dangerously",
28
+ resources: "usable"
29
+ }, options||{})
30
+
15
31
  return import("jsdom").then(({JSDOM}) => {
16
32
  const {window} = new JSDOM(`<html>
17
33
  <head>
18
34
  </head>
19
35
  <body>
20
36
  <div id="mocks"></div>
21
- </body>`, {
22
- pretendToBeVisual: true,
23
- contentType: "text/html",
24
- includeNodeLocations: true,
25
- storageQuota: 10000000
26
- });
37
+ </body>`, options);
27
38
 
28
39
  g['window'] = window;
29
40
 
@@ -35,6 +46,7 @@ function initJSDOM() {
35
46
  'HTMLCollection',
36
47
  'NodeList',
37
48
  'ElementInternals',
49
+ 'HTMLDocument',
38
50
  'HTMLFormElement',
39
51
  'HTMLInputElement',
40
52
  'HTMLSelectElement',
@@ -44,7 +56,6 @@ function initJSDOM() {
44
56
  'Node',
45
57
  'ShadowRoot',
46
58
  'Event',
47
- 'fetch',
48
59
  'CustomEvent',
49
60
  'Element',
50
61
  'HTMLElement',
@@ -59,8 +70,11 @@ function initJSDOM() {
59
70
  'NodeFilter',
60
71
  'navigator',
61
72
  'InputEvent',
73
+ 'Blob',
62
74
  'CustomEvent'
63
- ].forEach(key => (g[key] = window[key]));
75
+ ].forEach(key => {
76
+ g[key] = window[key]
77
+ });
64
78
 
65
79
  resolve();
66
80
  })
@@ -0,0 +1,81 @@
1
+ function createStorage() {
2
+ let UNSET = Symbol();
3
+ let s = {},
4
+ noopCallback = () => {
5
+ },
6
+ _itemInsertionCallback = noopCallback;
7
+
8
+ Object.defineProperty(s, 'setItem', {
9
+ get: () => {
10
+ return (k, v = UNSET) => {
11
+ if (v === UNSET) {
12
+ throw new TypeError(`Failed to execute 'setItem' on 'Storage': 2 arguments required, but only 1 present.`);
13
+ }
14
+ k = k + '';
15
+ if (!s.hasOwnProperty(k)) {
16
+ _itemInsertionCallback(s.length);
17
+ }
18
+ s[k] = v + '';
19
+ };
20
+ }
21
+ });
22
+ Object.defineProperty(s, 'getItem', {
23
+ get: () => {
24
+ return k => {
25
+ k = k + '';
26
+ if (s.hasOwnProperty(k)) {
27
+ return s[k];
28
+ } else {
29
+ return null;
30
+ }
31
+ };
32
+ }
33
+ });
34
+ Object.defineProperty(s, 'removeItem', {
35
+ get: () => {
36
+ return k => {
37
+ k = k + '';
38
+ if (s.hasOwnProperty(k)) {
39
+ delete s[k];
40
+ }
41
+ };
42
+ }
43
+ });
44
+ Object.defineProperty(s, 'clear', {
45
+ get: () => {
46
+ return () => {
47
+ for (let k in s) {
48
+ if (s.hasOwnProperty(k)) {
49
+ delete s[k];
50
+ }
51
+ }
52
+ };
53
+ }
54
+ });
55
+ Object.defineProperty(s, 'length', {
56
+ get: () => {
57
+ return Object.keys(s).length;
58
+ }
59
+ });
60
+ Object.defineProperty(s, "key", {
61
+ value: k => {
62
+ let key = Object.keys(s)[k];
63
+ return (!key) ? null : key;
64
+ },
65
+ });
66
+ Object.defineProperty(s, 'itemInsertionCallback', {
67
+ get: () => {
68
+ return _itemInsertionCallback;
69
+ },
70
+ set: v => {
71
+ if (!v || typeof v != 'function') {
72
+ v = noopCallback;
73
+ }
74
+ _itemInsertionCallback = v;
75
+ }
76
+ });
77
+ return s;
78
+ }
79
+
80
+
81
+ export {createStorage};