@schukai/monster 1.20.0 → 1.21.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. package/CHANGELOG +24 -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 +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/diff.js +1 -1
  15. package/dist/modules/data/extend.js +2 -2
  16. package/dist/modules/data/namespace.js +1 -1
  17. package/dist/modules/data/pathfinder.js +1 -1
  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 +2 -2
  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 +1 -1
  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 +1 -1
  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 +1 -1
  37. package/dist/modules/i18n/translations.js +1 -1
  38. package/dist/modules/logging/handler/console.js +1 -1
  39. package/dist/modules/logging/handler/namespace.js +1 -1
  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 +1 -1
  44. package/dist/modules/math/namespace.js +1 -1
  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 +1 -1
  50. package/dist/modules/types/base.js +1 -1
  51. package/dist/modules/types/basewithoptions.js +1 -1
  52. package/dist/modules/types/binary.js +1 -1
  53. package/dist/modules/types/dataurl.js +1 -1
  54. package/dist/modules/types/global.js +1 -1
  55. package/dist/modules/types/id.js +1 -1
  56. package/dist/modules/types/is.js +1 -1
  57. package/dist/modules/types/mediatype.js +1 -1
  58. package/dist/modules/types/namespace.js +1 -1
  59. package/dist/modules/types/observer.js +1 -1
  60. package/dist/modules/types/observerlist.js +1 -1
  61. package/dist/modules/types/proxyobserver.js +1 -1
  62. package/dist/modules/types/queue.js +1 -1
  63. package/dist/modules/types/randomid.js +1 -1
  64. package/dist/modules/types/stack.js +1 -1
  65. package/dist/modules/types/tokenlist.js +1 -1
  66. package/dist/modules/types/typeof.js +1 -1
  67. package/dist/modules/types/uniquequeue.js +1 -1
  68. package/dist/modules/types/validate.js +1 -1
  69. package/dist/modules/types/version.js +2 -2
  70. package/dist/modules/util/clone.js +2 -2
  71. package/dist/modules/util/comparator.js +1 -1
  72. package/dist/modules/util/freeze.js +1 -1
  73. package/dist/modules/util/namespace.js +1 -1
  74. package/dist/modules/util/processing.js +2 -0
  75. package/dist/monster.dev.js +389 -308
  76. package/dist/monster.dev.js.map +1 -1
  77. package/dist/monster.js +2 -2
  78. package/package.json +1 -5
  79. package/source/constraints/andoperator.js +5 -5
  80. package/source/constraints/invalid.js +3 -3
  81. package/source/constraints/isarray.js +3 -3
  82. package/source/constraints/isobject.js +3 -3
  83. package/source/constraints/oroperator.js +5 -5
  84. package/source/constraints/valid.js +3 -3
  85. package/source/data/buildmap.js +4 -4
  86. package/source/data/diff.js +3 -3
  87. package/source/data/extend.js +9 -9
  88. package/source/data/pathfinder.js +4 -4
  89. package/source/data/pipe.js +3 -3
  90. package/source/data/transformer.js +4 -4
  91. package/source/dom/assembler.js +2 -2
  92. package/source/dom/attributes.js +24 -24
  93. package/source/dom/customcontrol.js +2 -2
  94. package/source/dom/customelement.js +61 -4
  95. package/source/dom/events.js +4 -4
  96. package/source/dom/locale.js +2 -2
  97. package/source/dom/template.js +4 -4
  98. package/source/dom/theme.js +3 -3
  99. package/source/dom/updater.js +3 -3
  100. package/source/dom/util.js +6 -6
  101. package/source/i18n/locale.js +4 -4
  102. package/source/i18n/provider.js +2 -2
  103. package/source/i18n/providers/fetch.js +2 -2
  104. package/source/i18n/translations.js +2 -2
  105. package/source/logging/handler/console.js +2 -2
  106. package/source/logging/handler.js +2 -2
  107. package/source/logging/logentry.js +2 -2
  108. package/source/logging/logger.js +2 -2
  109. package/source/math/random.js +2 -2
  110. package/source/namespace.js +1 -1
  111. package/source/text/formatter.js +2 -2
  112. package/source/types/base.js +2 -2
  113. package/source/types/basewithoptions.js +2 -2
  114. package/source/types/binary.js +4 -4
  115. package/source/types/dataurl.js +4 -4
  116. package/source/types/global.js +4 -4
  117. package/source/types/id.js +2 -2
  118. package/source/types/is.js +20 -20
  119. package/source/types/mediatype.js +4 -4
  120. package/source/types/observer.js +3 -3
  121. package/source/types/observerlist.js +2 -2
  122. package/source/types/proxyobserver.js +5 -5
  123. package/source/types/queue.js +3 -3
  124. package/source/types/randomid.js +2 -2
  125. package/source/types/stack.js +2 -2
  126. package/source/types/tokenlist.js +2 -2
  127. package/source/types/typeof.js +3 -3
  128. package/source/types/uniquequeue.js +2 -2
  129. package/source/types/validate.js +20 -20
  130. package/source/types/version.js +6 -6
  131. package/source/util/clone.js +16 -6
  132. package/source/util/comparator.js +3 -3
  133. package/source/util/freeze.js +2 -2
  134. package/source/util/processing.js +197 -0
  135. package/test/cases/data/extend.js +9 -0
  136. package/test/cases/monster.js +1 -1
  137. package/test/cases/util/clone.js +31 -0
  138. package/test/cases/util/freeze.js +25 -0
  139. package/test/cases/util/processing.js +110 -0
  140. package/test/web/import.js +2 -0
  141. package/test/web/monster-dev.html +3 -3
  142. package/test/web/monster.html +2 -2
  143. package/test/web/test.html +3 -3
  144. package/test/web/tests.js +3 -3
@@ -25,7 +25,7 @@ import {
25
25
  *
26
26
  * ```
27
27
  * <script type="module">
28
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
28
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
29
29
  * console.log(Monster.Types.validateIterable('2')) // ↦ TypeError
30
30
  * console.log(Monster.Types.validateIterable([])) // ↦ value
31
31
  * </script>
@@ -35,7 +35,7 @@ import {
35
35
  *
36
36
  * ```
37
37
  * <script type="module">
38
- * import {validateIterable} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
38
+ * import {validateIterable} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
39
39
  * console.log(validateIterable('2')) // ↦ TypeError
40
40
  * console.log(validateIterable([])) // ↦ value
41
41
  * </script>
@@ -65,7 +65,7 @@ function validateIterable(value) {
65
65
  *
66
66
  * ```
67
67
  * <script type="module">
68
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
68
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
69
69
  * console.log(Monster.Types.validatePrimitive('2')) // ↦ value
70
70
  * console.log(Monster.Types.validatePrimitive([])) // ↦ TypeError
71
71
  * </script>
@@ -75,7 +75,7 @@ function validateIterable(value) {
75
75
  *
76
76
  * ```
77
77
  * <script type="module">
78
- * import {validatePrimitive} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
78
+ * import {validatePrimitive} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
79
79
  * console.log(validatePrimitive('2')) // ↦ value
80
80
  * console.log(validatePrimitive([])) // ↦ TypeError
81
81
  * </script>
@@ -105,7 +105,7 @@ function validatePrimitive(value) {
105
105
  *
106
106
  * ```
107
107
  * <script type="module">
108
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
108
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
109
109
  * console.log(Monster.Types.validateBoolean(true)) // ↦ value
110
110
  * console.log(Monster.Types.validateBoolean('2')) // ↦ TypeError
111
111
  * console.log(Monster.Types.validateBoolean([])) // ↦ TypeError
@@ -116,7 +116,7 @@ function validatePrimitive(value) {
116
116
  *
117
117
  * ```
118
118
  * <script type="module">
119
- * import {validateBoolean} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
119
+ * import {validateBoolean} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
120
120
  * console.log(validateBoolean(false)) // ↦ value
121
121
  * console.log(validateBoolean('2')) // ↦ TypeError
122
122
  * console.log(validateBoolean([])) // ↦ TypeError
@@ -145,7 +145,7 @@ function validateBoolean(value) {
145
145
  *
146
146
  * ```
147
147
  * <script type="module">
148
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
148
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
149
149
  * console.log(Monster.Types.validateString('2')) // ↦ value
150
150
  * console.log(Monster.Types.validateString([])) // ↦ TypeError
151
151
  * </script>
@@ -155,7 +155,7 @@ function validateBoolean(value) {
155
155
  *
156
156
  * ```
157
157
  * <script type="module">
158
- * import {validateString} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
158
+ * import {validateString} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
159
159
  * console.log(validateString('2')) // ↦ value
160
160
  * console.log(validateString([])) // ↦ TypeError
161
161
  * </script>
@@ -183,7 +183,7 @@ function validateString(value) {
183
183
  *
184
184
  * ```
185
185
  * <script type="module">
186
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
186
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
187
187
  * console.log(Monster.Types.validateObject({})) // ↦ value
188
188
  * console.log(Monster.Types.validateObject('2')) // ↦ TypeError
189
189
  * console.log(Monster.Types.validateObject([])) // ↦ TypeError
@@ -194,7 +194,7 @@ function validateString(value) {
194
194
  *
195
195
  * ```
196
196
  * <script type="module">
197
- * import {validateObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
197
+ * import {validateObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
198
198
  * console.log(validateObject({})) // ↦ value
199
199
  * console.log(validateObject('2')) // ↦ TypeError
200
200
  * console.log(validateObject([])) // ↦ TypeError
@@ -222,7 +222,7 @@ function validateObject(value) {
222
222
  *
223
223
  * ```
224
224
  * <script type="module">
225
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
225
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
226
226
  * console.log(Monster.Types.validateInstance({}, Object)) // ↦ value
227
227
  * console.log(Monster.Types.validateInstance('2', Object)) // ↦ TypeError
228
228
  * console.log(Monster.Types.validateInstance([], Object)) // ↦ TypeError
@@ -233,7 +233,7 @@ function validateObject(value) {
233
233
  *
234
234
  * ```
235
235
  * <script type="module">
236
- * import {validateInstance} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
236
+ * import {validateInstance} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
237
237
  * console.log(validateInstance({}, Object)) // ↦ value
238
238
  * console.log(validateInstance('2', Object)) // ↦ TypeError
239
239
  * console.log(validateInstance([], Object)) // ↦ TypeError
@@ -270,7 +270,7 @@ function validateInstance(value, instance) {
270
270
  *
271
271
  * ```
272
272
  * <script type="module">
273
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
273
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
274
274
  * console.log(Monster.Types.validateArray('2')) // ↦ TypeError
275
275
  * console.log(Monster.Types.validateArray([])) // ↦ value
276
276
  * </script>
@@ -280,7 +280,7 @@ function validateInstance(value, instance) {
280
280
  *
281
281
  * ```
282
282
  * <script type="module">
283
- * import {validateArray} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
283
+ * import {validateArray} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
284
284
  * console.log(validateArray('2')) // ↦ TypeError
285
285
  * console.log(validateArray([])) // ↦ value
286
286
  * </script>
@@ -307,7 +307,7 @@ function validateArray(value) {
307
307
  *
308
308
  * ```
309
309
  * <script type="module">
310
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
310
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
311
311
  * console.log(Monster.Types.validateSymbol('2')) // ↦ TypeError
312
312
  * console.log(Monster.Types.validateSymbol([])) // ↦ value
313
313
  * </script>
@@ -317,7 +317,7 @@ function validateArray(value) {
317
317
  *
318
318
  * ```
319
319
  * <script type="module">
320
- * import {validateSymbol} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
320
+ * import {validateSymbol} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
321
321
  * console.log(validateSymbol('2')) // ↦ TypeError
322
322
  * console.log(validateSymbol()) // ↦ value
323
323
  * </script>
@@ -344,7 +344,7 @@ function validateSymbol(value) {
344
344
  *
345
345
  * ```
346
346
  * <script type="module">
347
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
347
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
348
348
  * console.log(Monster.Types.validateFunction(()=>{})) // ↦ value
349
349
  * console.log(Monster.Types.validateFunction('2')) // ↦ TypeError
350
350
  * console.log(Monster.Types.validateFunction([])) // ↦ TypeError
@@ -355,7 +355,7 @@ function validateSymbol(value) {
355
355
  *
356
356
  * ```
357
357
  * <script type="module">
358
- * import {validateFunction} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
358
+ * import {validateFunction} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
359
359
  * console.log(validateFunction(()=>{})) // ↦ value
360
360
  * console.log(validateFunction('2')) // ↦ TypeError
361
361
  * console.log(validateFunction([])) // ↦ TypeError
@@ -383,7 +383,7 @@ function validateFunction(value) {
383
383
  *
384
384
  * ```
385
385
  * <script type="module">
386
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
386
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
387
387
  * console.log(Monster.Types.validateInteger(true)) // ↦ TypeError
388
388
  * console.log(Monster.Types.validateInteger('2')) // ↦ TypeError
389
389
  * console.log(Monster.Types.validateInteger(2)) // ↦ value
@@ -394,7 +394,7 @@ function validateFunction(value) {
394
394
  *
395
395
  * ```
396
396
  * <script type="module">
397
- * import {validateFunction} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/validate.js';
397
+ * import {validateFunction} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/validate.js';
398
398
  * console.log(validateInteger(true)) // ↦ TypeError
399
399
  * console.log(validateInteger('2')) // ↦ TypeError
400
400
  * console.log(validateInteger(2)) // ↦ value
@@ -10,7 +10,7 @@ import {Base} from './base.js';
10
10
  *
11
11
  * ```
12
12
  * <script type="module">
13
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/version.js';
13
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/version.js';
14
14
  * console.log(new Monster.Types.Version('1.2.3')) // ↦ 1.2.3
15
15
  * console.log(new Monster.Types.Version('1')) // ↦ 1.0.0
16
16
  * </script>
@@ -20,7 +20,7 @@ import {Base} from './base.js';
20
20
  *
21
21
  * ```
22
22
  * <script type="module">
23
- * import {Version} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/version.js';
23
+ * import {Version} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/version.js';
24
24
  * console.log(new Version('1.2.3')) // ↦ 1.2.3
25
25
  * console.log(new Version('1')) // ↦ 1.0.0
26
26
  * </script>
@@ -28,7 +28,7 @@ import {Base} from './base.js';
28
28
  *
29
29
  * @example
30
30
  *
31
- * import {Version} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/version.js';
31
+ * import {Version} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/version.js';
32
32
  *
33
33
  * new Version('1.0.0') // ↦ 1.0.0
34
34
  * new Version(1) // ↦ 1.0.0
@@ -151,7 +151,7 @@ let monsterVersion;
151
151
  *
152
152
  * ```
153
153
  * <script type="module">
154
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/version.js';
154
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/version.js';
155
155
  * console.log(Monster.getVersion())
156
156
  * </script>
157
157
  * ```
@@ -160,7 +160,7 @@ let monsterVersion;
160
160
  *
161
161
  * ```
162
162
  * <script type="module">
163
- * import {getVersion} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/version.js';
163
+ * import {getVersion} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/types/version.js';
164
164
  * console.log(getVersion())
165
165
  * </script>
166
166
  * ```
@@ -176,7 +176,7 @@ function getVersion() {
176
176
  return monsterVersion;
177
177
  }
178
178
  /**#@+ dont touch, replaced by make with package.json version */
179
- monsterVersion = new Version('1.20.0')
179
+ monsterVersion = new Version('1.21.1')
180
180
  /**#@-*/
181
181
 
182
182
  return monsterVersion;
@@ -7,6 +7,8 @@
7
7
  import {assignToNamespace, Monster} from '../namespace.js';
8
8
  import {getGlobal} from '../types/global.js';
9
9
  import {isArray, isFunction, isObject, isPrimitive} from '../types/is.js';
10
+ import {typeOf} from "../types/typeof.js";
11
+ import {validateObject} from "../types/validate.js";
10
12
 
11
13
 
12
14
  /**
@@ -22,7 +24,7 @@ import {isArray, isFunction, isObject, isPrimitive} from '../types/is.js';
22
24
  *
23
25
  * ```
24
26
  * <script type="module">
25
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/util/clone.js';
27
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/util/clone.js';
26
28
  * console.log(Monster.Util.clone({}))
27
29
  * </script>
28
30
  * ```
@@ -31,7 +33,7 @@ import {isArray, isFunction, isObject, isPrimitive} from '../types/is.js';
31
33
  *
32
34
  * ```
33
35
  * <script type="module">
34
- * import {clone} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/util/clone.js';
36
+ * import {clone} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/util/clone.js';
35
37
  * console.log(clone({}))
36
38
  * </script>
37
39
  * ```
@@ -117,14 +119,22 @@ function clone(obj) {
117
119
  * @private
118
120
  */
119
121
  function cloneObject(obj) {
120
- var copy;
122
+
123
+ validateObject(obj);
124
+
125
+ const constructor = obj?.['constructor'];
121
126
 
122
127
  /** Object has clone method */
123
- if (typeof obj.hasOwnProperty('getClone') && obj.getClone === 'function') {
124
- return obj.getClone();
128
+ if(typeOf(constructor)==='function') {
129
+ const prototype = constructor?.prototype;
130
+ if(typeof prototype==='object') {
131
+ if(prototype.hasOwnProperty('getClone')&& typeOf(obj.getClone) === 'function') {
132
+ return obj.getClone();
133
+ }
134
+ }
125
135
  }
126
136
 
127
- copy = {};
137
+ let copy = {};
128
138
  if (typeof obj.constructor === 'function' &&
129
139
  typeof obj.constructor.call === 'function') {
130
140
  copy = new obj.constructor();
@@ -12,7 +12,7 @@ import {isFunction} from '../types/is.js';
12
12
  *
13
13
  * ```
14
14
  * <script type="module">
15
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/util/comparator.js';
15
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/util/comparator.js';
16
16
  * console.log(new Monster.Util.Comparator())
17
17
  * </script>
18
18
  * ```
@@ -21,7 +21,7 @@ import {isFunction} from '../types/is.js';
21
21
  *
22
22
  * ```
23
23
  * <script type="module">
24
- * import {Comparator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/util/comparator.js';
24
+ * import {Comparator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/util/comparator.js';
25
25
  * console.log(new Comparator())
26
26
  * </script>
27
27
  * ```
@@ -46,7 +46,7 @@ import {isFunction} from '../types/is.js';
46
46
  *
47
47
  * @example
48
48
  *
49
- * import {Comparator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/util/comparator.js';
49
+ * import {Comparator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/util/comparator.js';
50
50
  *
51
51
  * console.log(new Comparator().lessThanOrEqual(2, 5))
52
52
  * // ↦ true
@@ -14,7 +14,7 @@ import {validateObject} from '../types/validate.js';
14
14
  *
15
15
  * ```
16
16
  * <script type="module">
17
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/util/freeze.js';
17
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/util/freeze.js';
18
18
  * console.log(Monster.Util.deepFreeze({}))
19
19
  * </script>
20
20
  * ```
@@ -23,7 +23,7 @@ import {validateObject} from '../types/validate.js';
23
23
  *
24
24
  * ```
25
25
  * <script type="module">
26
- * import {deepFreeze} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/util/freeze.js';
26
+ * import {deepFreeze} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/util/freeze.js';
27
27
  * console.log(deepFreeze({}))
28
28
  * </script>
29
29
  * ```
@@ -0,0 +1,197 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @author schukai GmbH
5
+ */
6
+
7
+ import {PROPERTY_KEY_INTERNALDATA} from "../constants.js";
8
+ import {assignToNamespace, Monster} from '../namespace.js';
9
+ import {Base} from "../types/base.js";
10
+ import {getGlobalFunction} from "../types/global.js";
11
+ import {isFunction, isInteger} from "../types/is.js";
12
+ import {Queue} from "../types/queue.js";
13
+ import {validateFunction, validateInteger} from "../types/validate.js";
14
+
15
+
16
+ /**
17
+ * @private
18
+ * @type {symbol}
19
+ */
20
+ const internalDataSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
21
+
22
+ /**
23
+ * @private
24
+ */
25
+ class Callback {
26
+
27
+ /**
28
+ *
29
+ * @param {function} callback
30
+ * @param {integer|undefined} time
31
+ * @throws {TypeError} value is not a function
32
+ * @throws {TypeError} value is not an integer
33
+ * @private
34
+ */
35
+ constructor(callback, time) {
36
+ this[internalDataSymbol] = {
37
+ callback: validateFunction(callback),
38
+ time: validateInteger(time ?? 0)
39
+ };
40
+ }
41
+
42
+ /**
43
+ * @private
44
+ * @param {*} data
45
+ * @return {Promise}
46
+ */
47
+ run(data) {
48
+ const self = this;
49
+ return new Promise((resolve, reject) => {
50
+
51
+ getGlobalFunction('setTimeout')(() => {
52
+ try {
53
+ resolve(self[internalDataSymbol].callback(data));
54
+ } catch (e) {
55
+ reject(e);
56
+ }
57
+
58
+ },
59
+ self[internalDataSymbol].time);
60
+
61
+
62
+ })
63
+
64
+ }
65
+ }
66
+
67
+ /**
68
+ * This class allows to execute several functions in order.
69
+ *
70
+ * Functions and timeouts can be passed. If a timeout is passed, it applies to all further functions.
71
+ * In the example
72
+ *
73
+ * `timeout1, function1, function2, function3, timeout2, function4`
74
+ *
75
+ * the timeout1 is valid for the functions 1, 2 and 3 and the timeout2 for the function4.
76
+ *
77
+ * So the execution time is timeout1+timeout1+timeout1+timeout2
78
+ *
79
+ * The result of `run()` is a promise.
80
+ *
81
+ * You can create an instance via the monster namespace `Monster.Util.Processing()`.
82
+ *
83
+ * ```
84
+ * <script type="module">
85
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/util/processing.js';
86
+ * new Monster.Util.Processing()
87
+ * </script>
88
+ * ```
89
+ *
90
+ * Alternatively, you can also integrate this class individually.
91
+ *
92
+ * ```
93
+ * <script type="module">
94
+ * import {Processing} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/util/processing.js';
95
+ * new Processing();
96
+ * </script>
97
+ * ```
98
+ *
99
+ * @example
100
+ * import {Processing} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/util/processing.js';
101
+ *
102
+ * let startTime = +new Date();
103
+ *
104
+ * new Processing((url)=>{
105
+ * return fetch(url)
106
+ * },(response)=>{
107
+ * // do something with the response
108
+ * console.log(response.status, +new Date()-startTime)
109
+ * },200,()=>{
110
+ * // this function is called 200 seconds after fetch is received.
111
+ * console.log('finished', +new Date()-startTime)
112
+ * }).run('https://monsterjs.org/assets/world.json').then(r=>{
113
+ * console.log(r)
114
+ * })
115
+ *
116
+ * @copyright schukai GmbH
117
+ * @since 1.21.0
118
+ * @memberOf Monster.Util
119
+ * @summary Class to be able to execute function chains
120
+ */
121
+ class Processing extends Base {
122
+
123
+ /**
124
+ * Create new Processing
125
+ *
126
+ * Functions and timeouts can be passed. If a timeout is passed, it applies to all further functions.
127
+ * In the example
128
+ *
129
+ * `timeout1, function1, function2, function3, timeout2, function4`
130
+ *
131
+ * the timeout1 is valid for the functions 1, 2 and 3 and the timeout2 for the function4.
132
+ *
133
+ * So the execution time is timeout1+timeout1+timeout1+timeout2
134
+ *
135
+ * @param {timeout} timeout Timeout
136
+ * @param {function} callback Callback
137
+ * @throw {TypeError} the arguments must be either integer or functions
138
+ */
139
+ constructor() {
140
+ super();
141
+
142
+ this[internalDataSymbol] = {
143
+ queue: new Queue
144
+ };
145
+
146
+ let time = 0
147
+
148
+ for (const [, arg] of Object.entries(arguments)) {
149
+ if (isInteger(arg) && arg >= 0) {
150
+ time = arg;
151
+ } else if (isFunction(arg)) {
152
+ this[internalDataSymbol].queue.add(new Callback(arg, time))
153
+ } else {
154
+ throw new TypeError('the arguments must be either integer or functions')
155
+ }
156
+ }
157
+
158
+
159
+ }
160
+
161
+ /**
162
+ * Adds a function with the desired timeout
163
+ * If no timeout is specified, the timeout of the previous function is used.
164
+ *
165
+ * @param {function} callback
166
+ * @param {integer|undefined} time
167
+ * @throws {TypeError} value is not a function
168
+ * @throws {TypeError} value is not an integer
169
+ */
170
+ add(callback, time) {
171
+ this[internalDataSymbol].queue.add(new Callback(callback, time))
172
+ return this;
173
+ }
174
+
175
+
176
+ /**
177
+ * Executes the defined functions in order.
178
+ *
179
+ * @param {*} data
180
+ * @return {Promise}
181
+ */
182
+ run(data) {
183
+ const self = this;
184
+ if (this[internalDataSymbol].queue.isEmpty()) {
185
+ return Promise.resolve(data);
186
+ }
187
+
188
+ return this[internalDataSymbol].queue.poll().run(data).then((result)=>{
189
+ return self.run(result);
190
+ });
191
+
192
+ }
193
+
194
+ }
195
+
196
+ assignToNamespace('Monster.Util', Processing);
197
+ export {Monster, Processing}
@@ -3,9 +3,18 @@
3
3
  import {extend} from "../../../source/data/extend.js";
4
4
  import {expect} from "chai"
5
5
 
6
+ class MockForExtends {
7
+ constructor() {
8
+ }
9
+ }
10
+
11
+
6
12
  describe('extend', function () {
7
13
 
8
14
  [
15
+ [
16
+ '{"thekey":{}}',{},{thekey:new MockForExtends}
17
+ ],
9
18
  [
10
19
  '{"a":{"b":["1","2","3"]}}',
11
20
  {
@@ -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.20.0')
12
+ monsterVersion = new Version('1.21.1')
13
13
  /**#@-*/
14
14
 
15
15
  let m = Monster.getVersion();
@@ -12,7 +12,38 @@ describe('Clone', function () {
12
12
 
13
13
  }
14
14
  }
15
+
16
+ class B {
17
+ constructor(b) {
18
+ this.b = b
19
+ }
20
+
21
+ a() {
22
+
23
+ }
24
+
25
+ getClone() {
26
+ return "DONE"
27
+ }
28
+
29
+ }
15
30
 
31
+ describe('.clone(B) with getClone', function () {
32
+ it('.clone(B) should object', function () {
33
+ let b = new B({
34
+ x: {
35
+ y: 1, d: new A(1), z: () => {
36
+ }
37
+ }
38
+ });
39
+ let r = clone(b);
40
+ expect(b).to.be.instanceOf(B)
41
+ expect(r).not.equal(b);
42
+ expect(JSON.stringify(r)).equal(JSON.stringify('DONE'));
43
+
44
+ });
45
+ })
46
+
16
47
  describe('.clone(A)', function () {
17
48
  it('.clone(A) should object', function () {
18
49
  let a = new A({
@@ -0,0 +1,25 @@
1
+ import {expect} from "chai"
2
+ import {deepFreeze} from "../../../source/util/freeze.js";
3
+
4
+
5
+ describe('deepFreeze', function () {
6
+
7
+ describe('deepFreeze an object', function () {
8
+
9
+ it('should freeze object', function () {
10
+
11
+ let obj1 = {
12
+ a: {
13
+ b: {}
14
+ }
15
+ };
16
+
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);
20
+ });
21
+
22
+ });
23
+
24
+
25
+ });