@schukai/monster 1.25.0 → 1.28.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. package/CHANGELOG +43 -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 +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 +1 -1
  17. package/dist/modules/data/datasource/restapi.js +1 -1
  18. package/dist/modules/data/datasource/storage/localstorage.js +1 -1
  19. package/dist/modules/data/datasource/storage/namespace.js +1 -1
  20. package/dist/modules/data/datasource/storage/sessionstorage.js +1 -1
  21. package/dist/modules/data/datasource/storage.js +1 -1
  22. package/dist/modules/data/datasource.js +1 -1
  23. package/dist/modules/data/diff.js +1 -1
  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 +1 -1
  27. package/dist/modules/data/pipe.js +1 -1
  28. package/dist/modules/data/transformer.js +1 -1
  29. package/dist/modules/dom/assembler.js +1 -1
  30. package/dist/modules/dom/attributes.js +2 -2
  31. package/dist/modules/dom/constants.js +2 -2
  32. package/dist/modules/dom/customcontrol.js +1 -1
  33. package/dist/modules/dom/customelement.js +1 -1
  34. package/dist/modules/dom/events.js +1 -1
  35. package/dist/modules/dom/focusmanager.js +1 -1
  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 +1 -1
  39. package/dist/modules/dom/resource/link/stylesheet.js +1 -1
  40. package/dist/modules/dom/resource/link.js +1 -1
  41. package/dist/modules/dom/resource/script.js +1 -1
  42. package/dist/modules/dom/resource.js +1 -1
  43. package/dist/modules/dom/resourcemanager.js +1 -1
  44. package/dist/modules/dom/template.js +2 -2
  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 +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -1
  82. package/dist/modules/types/proxyobserver.js +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -1
  94. package/dist/modules/util/comparator.js +1 -1
  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 +1 -1
  98. package/dist/modules/util/trimspaces.js +1 -1
  99. package/dist/monster.dev.js +1181 -708
  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/constraints/abstract.js +5 -0
  104. package/source/constraints/abstractoperator.js +5 -0
  105. package/source/constraints/andoperator.js +10 -5
  106. package/source/constraints/invalid.js +8 -3
  107. package/source/constraints/isarray.js +9 -4
  108. package/source/constraints/isobject.js +8 -3
  109. package/source/constraints/oroperator.js +10 -5
  110. package/source/constraints/valid.js +8 -3
  111. package/source/data/buildmap.js +27 -13
  112. package/source/data/buildtree.js +129 -0
  113. package/source/data/datasource/restapi.js +3 -3
  114. package/source/data/datasource/storage/localstorage.js +2 -2
  115. package/source/data/datasource/storage/sessionstorage.js +2 -2
  116. package/source/data/datasource/storage.js +3 -3
  117. package/source/data/datasource.js +3 -3
  118. package/source/data/diff.js +3 -3
  119. package/source/data/extend.js +2 -2
  120. package/source/data/pathfinder.js +4 -4
  121. package/source/data/pipe.js +3 -3
  122. package/source/data/transformer.js +3 -3
  123. package/source/dom/assembler.js +2 -2
  124. package/source/dom/attributes.js +111 -28
  125. package/source/dom/constants.js +17 -1
  126. package/source/dom/customcontrol.js +1 -1
  127. package/source/dom/customelement.js +1 -1
  128. package/source/dom/events.js +6 -7
  129. package/source/dom/focusmanager.js +6 -7
  130. package/source/dom/locale.js +8 -4
  131. package/source/dom/resource/data.js +2 -2
  132. package/source/dom/resource/link/stylesheet.js +2 -2
  133. package/source/dom/resource/link.js +2 -2
  134. package/source/dom/resource/script.js +2 -2
  135. package/source/dom/resource.js +2 -2
  136. package/source/dom/resourcemanager.js +2 -2
  137. package/source/dom/template.js +55 -15
  138. package/source/dom/theme.js +3 -3
  139. package/source/dom/updater.js +158 -98
  140. package/source/dom/util.js +6 -6
  141. package/source/dom/worker/factory.js +2 -2
  142. package/source/i18n/formatter.js +140 -0
  143. package/source/i18n/locale.js +6 -4
  144. package/source/i18n/provider.js +2 -2
  145. package/source/i18n/providers/fetch.js +18 -3
  146. package/source/i18n/translations.js +18 -9
  147. package/source/logging/handler/console.js +2 -2
  148. package/source/logging/handler.js +2 -2
  149. package/source/logging/logentry.js +2 -2
  150. package/source/logging/logger.js +2 -2
  151. package/source/math/random.js +2 -2
  152. package/source/namespace.js +1 -1
  153. package/source/text/formatter.js +190 -48
  154. package/source/types/base.js +2 -2
  155. package/source/types/basewithoptions.js +2 -2
  156. package/source/types/binary.js +4 -4
  157. package/source/types/dataurl.js +4 -4
  158. package/source/types/global.js +4 -4
  159. package/source/types/id.js +6 -3
  160. package/source/types/is.js +100 -82
  161. package/source/types/mediatype.js +4 -4
  162. package/source/types/node.js +210 -0
  163. package/source/types/nodelist.js +129 -0
  164. package/source/types/noderecursiveiterator.js +148 -0
  165. package/source/types/observer.js +3 -3
  166. package/source/types/observerlist.js +2 -2
  167. package/source/types/proxyobserver.js +5 -5
  168. package/source/types/queue.js +4 -4
  169. package/source/types/randomid.js +2 -2
  170. package/source/types/regex.js +49 -0
  171. package/source/types/stack.js +2 -2
  172. package/source/types/tokenlist.js +2 -2
  173. package/source/types/typeof.js +3 -3
  174. package/source/types/uniquequeue.js +2 -2
  175. package/source/types/uuid.js +2 -2
  176. package/source/types/validate.js +20 -20
  177. package/source/types/version.js +6 -6
  178. package/source/util/clone.js +2 -2
  179. package/source/util/comparator.js +3 -3
  180. package/source/util/freeze.js +2 -2
  181. package/source/util/processing.js +3 -3
  182. package/source/util/trimspaces.js +2 -2
  183. package/test/cases/data/buildtree.js +212 -0
  184. package/test/cases/dom/attributes.js +46 -19
  185. package/test/cases/dom/resource/link/stylesheet.js +1 -1
  186. package/test/cases/dom/template.js +72 -14
  187. package/test/cases/dom/updater.js +102 -75
  188. package/test/cases/i18n/formatter.js +66 -0
  189. package/test/cases/monster.js +1 -1
  190. package/test/cases/text/formatter.js +36 -5
  191. package/test/cases/types/node.js +252 -0
  192. package/test/cases/types/nodelist.js +71 -0
  193. package/test/cases/types/noderecursiveiterator.js +75 -0
  194. package/test/cases/types/regex.js +32 -0
  195. package/test/util/jsdom.js +0 -1
  196. package/test/web/import.js +6 -0
  197. package/test/web/monster-dev.html +3 -3
  198. package/test/web/monster.html +2 -2
  199. package/test/web/test.html +3 -3
  200. package/test/web/tests.js +3 -3
@@ -7,16 +7,18 @@
7
7
  import {assignToNamespace, Monster} from '../namespace.js';
8
8
 
9
9
  /**
10
- * With this function you can check if a value is iterable
10
+ * With this function you can check if a value is iterable.
11
+ *
12
+ * This method is used in the library to have consistent names.
11
13
  *
12
14
  * You can call the method via the monster namespace `Monster.Types.isPrimitive()`.
13
15
  *
14
16
  * ```
15
17
  * <script type="module">
16
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
17
- * console.log(Monster.Types.isIterable(null)) // ↦ false
18
- * console.log(Monster.Types.isIterable('hello')) // ↦ true
19
- * console.log(Monster.Types.isIterable([])) // ↦ true
18
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/monster.js';
19
+ * Monster.Types.isIterable(null) // ↦ false
20
+ * Monster.Types.isIterable('hello') // ↦ true
21
+ * Monster.Types.isIterable([]) // ↦ true
20
22
  * </script>
21
23
  * ```
22
24
  *
@@ -24,7 +26,7 @@ import {assignToNamespace, Monster} from '../namespace.js';
24
26
  *
25
27
  * ```
26
28
  * <script type="module">
27
- * import {isIterable} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
29
+ * import {isIterable} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/modules/types/is.js';
28
30
  * isIterable(null) // ↦ false
29
31
  * isIterable('hello') // ↦ true
30
32
  * isIterable([]) // ↦ true
@@ -46,14 +48,16 @@ function isIterable(value) {
46
48
 
47
49
  /**
48
50
  * Checks whether the value passed is a primitive (string, number, boolean, NaN, undefined, null or symbol)
51
+ *
52
+ * This method is used in the library to have consistent names.
49
53
  *
50
54
  * You can call the method via the monster namespace `Monster.Types.isPrimitive()`.
51
55
  *
52
56
  * ```
53
57
  * <script type="module">
54
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
55
- * console.log(Monster.Types.isPrimitive('2')) // ↦ false
56
- * console.log(Monster.Types.isPrimitive([])) // ↦ true
58
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/monster.js';
59
+ * Monster.Types.isPrimitive('2') // ↦ false
60
+ * Monster.Types.isPrimitive([]) // ↦ true
57
61
  * </script>
58
62
  * ```
59
63
  *
@@ -61,9 +65,9 @@ function isIterable(value) {
61
65
  *
62
66
  * ```
63
67
  * <script type="module">
64
- * import {isPrimitive} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
65
- * console.log(isPrimitive('2')) // ↦ true
66
- * console.log(isPrimitive([])) // ↦ false
68
+ * import {isPrimitive} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/modules/types/is.js';
69
+ * isPrimitive('2')) // ↦ true
70
+ * isPrimitive([])) // ↦ false
67
71
  * </script>
68
72
  * ```
69
73
  *
@@ -91,14 +95,16 @@ function isPrimitive(value) {
91
95
 
92
96
  /**
93
97
  * Checks whether the value passed is a symbol
98
+ *
99
+ * This method is used in the library to have consistent names.
94
100
  *
95
101
  * You can call the method via the monster namespace `Monster.Types.isSymbol()`.
96
102
  *
97
103
  * ```
98
104
  * <script type="module">
99
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
100
- * console.log(Monster.Types.isSymbol('2')) // ↦ false
101
- * console.log(Monster.Types.isSymbol(Symbol('test')) // ↦ true
105
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/monster.js';
106
+ * Monster.Types.isSymbol('2') // ↦ false
107
+ * Monster.Types.isSymbol(Symbol('test') // ↦ true
102
108
  * </script>
103
109
  * ```
104
110
  *
@@ -106,9 +112,9 @@ function isPrimitive(value) {
106
112
  *
107
113
  * ```
108
114
  * <script type="module">
109
- * import {isSymbol} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
110
- * console.log(isSymbol(Symbol('a'))) // ↦ true
111
- * console.log(isSymbol([]) // ↦ false
115
+ * import {isSymbol} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/modules/types/is.js';
116
+ * isSymbol(Symbol('a'))) // ↦ true
117
+ * isSymbol([]) // ↦ false
112
118
  * </script>
113
119
  * ```
114
120
  *
@@ -123,16 +129,18 @@ function isSymbol(value) {
123
129
  }
124
130
 
125
131
  /**
126
- * Checks whether the value passed is a boolean
132
+ * Checks whether the value passed is a boolean.
133
+ *
134
+ * This method is used in the library to have consistent names.
127
135
  *
128
136
  * You can call the method via the monster namespace `Monster.Types.isBoolean()`.
129
137
  *
130
138
  * ```
131
139
  * <script type="module">
132
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
133
- * console.log(Monster.Types.isBoolean('2')) // ↦ false
134
- * console.log(Monster.Types.isBoolean([])) // ↦ false
135
- * console.log(Monster.Types.isBoolean(true)) // ↦ true
140
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/monster.js';
141
+ * Monster.Types.isBoolean('2') // ↦ false
142
+ * Monster.Types.isBoolean([]) // ↦ false
143
+ * Monster.Types.isBoolean(true) // ↦ true
136
144
  * </script>
137
145
  * ```
138
146
  *
@@ -140,10 +148,10 @@ function isSymbol(value) {
140
148
  *
141
149
  * ```
142
150
  * <script type="module">
143
- * import {isBoolean} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
144
- * console.log(isBoolean('2')) // ↦ false
145
- * console.log(isBoolean([])) // ↦ false
146
- * console.log(isBoolean(2>4)) // ↦ true
151
+ * import {isBoolean} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/modules/types/is.js';
152
+ * isBoolean('2')) // ↦ false
153
+ * isBoolean([])) // ↦ false
154
+ * isBoolean(2>4)) // ↦ true
147
155
  * </script>
148
156
  * ```
149
157
  *
@@ -163,15 +171,17 @@ function isBoolean(value) {
163
171
  }
164
172
 
165
173
  /**
166
- * checks whether the value passed is a string
174
+ * Checks whether the value passed is a string
175
+ *
176
+ * This method is used in the library to have consistent names.
167
177
  *
168
- * you can call the method via the monster namespace `Monster.Types.isString()`.
178
+ * You can call the method via the monster namespace `Monster.Types.isString()`.
169
179
  *
170
180
  * ```
171
181
  * <script type="module">
172
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
173
- * console.log(Monster.Types.isString('2')) // ↦ true
174
- * console.log(Monster.Types.isString([])) // ↦ false
182
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/monster.js';
183
+ * Monster.Types.isString('2') // ↦ true
184
+ * Monster.Types.isString([]) // ↦ false
175
185
  * </script>
176
186
  * ```
177
187
  *
@@ -179,9 +189,9 @@ function isBoolean(value) {
179
189
  *
180
190
  * ```
181
191
  * <script type="module">
182
- * import {isString} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
183
- * console.log(isString('2')) // ↦ true
184
- * console.log(isString([])) // ↦ false
192
+ * import {isString} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/modules/types/is.js';
193
+ * isString('2')) // ↦ true
194
+ * isString([])) // ↦ false
185
195
  * </script>
186
196
  * ```
187
197
  *
@@ -199,16 +209,18 @@ function isString(value) {
199
209
  }
200
210
 
201
211
  /**
202
- * checks whether the value passed is a object
212
+ * Checks whether the value passed is a object
213
+ *
214
+ * This method is used in the library to have consistent names.
203
215
  *
204
- * you can call the method via the monster namespace `Monster.Types.isObject()`.
216
+ * You can call the method via the monster namespace `Monster.Types.isObject()`.
205
217
  *
206
218
  * ```
207
219
  * <script type="module">
208
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
209
- * console.log(Monster.Types.isObject('2')) // ↦ false
210
- * console.log(Monster.Types.isObject([])) // ↦ false
211
- * console.log(Monster.Types.isObject({})) // ↦ true
220
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/monster.js';
221
+ * Monster.Types.isObject('2') // ↦ false
222
+ * Monster.Types.isObject([]) // ↦ false
223
+ * Monster.Types.isObject({}) // ↦ true
212
224
  * </script>
213
225
  * ```
214
226
  *
@@ -216,9 +228,9 @@ function isString(value) {
216
228
  *
217
229
  * ```
218
230
  * <script type="module">
219
- * import {isObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
220
- * console.log(isObject('2')) // ↦ false
221
- * console.log(isObject([])) // ↦ false
231
+ * import {isObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/modules/types/is.js';
232
+ * isObject('2')) // ↦ false
233
+ * isObject([])) // ↦ false
222
234
  * </script>
223
235
  * ```
224
236
  *
@@ -241,16 +253,18 @@ function isObject(value) {
241
253
  }
242
254
 
243
255
  /**
244
- * checks whether the value passed is a object and instance of instance
256
+ * Checks whether the value passed is a object and instance of instance.
257
+ *
258
+ * This method is used in the library to have consistent names.
245
259
  *
246
260
  * you can call the method via the monster namespace `Monster.Types.isInstance()`.
247
261
  *
248
262
  * ```
249
263
  * <script type="module">
250
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
251
- * console.log(Monster.Types.isInstance('2')) // ↦ false
252
- * console.log(Monster.Types.isInstance([])) // ↦ false
253
- * console.log(Monster.Types.isInstance({})) // ↦ true
264
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/monster.js';
265
+ * Monster.Types.isInstance('2') // ↦ false
266
+ * Monster.Types.isInstance([]) // ↦ false
267
+ * Monster.Types.isInstance({}) // ↦ true
254
268
  * </script>
255
269
  * ```
256
270
  *
@@ -258,9 +272,9 @@ function isObject(value) {
258
272
  *
259
273
  * ```
260
274
  * <script type="module">
261
- * import {isInstance} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
262
- * console.log(isInstance('2')) // ↦ false
263
- * console.log(isInstance([])) // ↦ false
275
+ * import {isInstance} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/modules/types/is.js';
276
+ * isInstance('2')) // ↦ false
277
+ * isInstance([])) // ↦ false
264
278
  * </script>
265
279
  * ```
266
280
  *
@@ -281,15 +295,17 @@ function isInstance(value, instance) {
281
295
  }
282
296
 
283
297
  /**
284
- * checks whether the value passed is a array
298
+ * Checks whether the value passed is a array
299
+ *
300
+ * This method is used in the library to have consistent names.
285
301
  *
286
302
  * you can call the method via the monster namespace `Monster.Types.isArray()`.
287
303
  *
288
304
  * ```
289
305
  * <script type="module">
290
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
291
- * console.log(Monster.Types.isArray('2')) // ↦ false
292
- * console.log(Monster.Types.isArray([])) // ↦ true
306
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/monster.js';
307
+ * Monster.Types.isArray('2') // ↦ false
308
+ * Monster.Types.isArray([]) // ↦ true
293
309
  * </script>
294
310
  * ```
295
311
  *
@@ -297,9 +313,9 @@ function isInstance(value, instance) {
297
313
  *
298
314
  * ```
299
315
  * <script type="module">
300
- * import {isArray} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
301
- * console.log(isArray('2')) // ↦ false
302
- * console.log(isArray([])) // ↦ true
316
+ * import {isArray} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/modules/types/is.js';
317
+ * isArray('2')) // ↦ false
318
+ * isArray([])) // ↦ true
303
319
  * </script>
304
320
  * ```
305
321
  *
@@ -308,25 +324,25 @@ function isInstance(value, instance) {
308
324
  * @since 1.0.0
309
325
  * @copyright schukai GmbH
310
326
  * @memberOf Monster.Types
327
+ * @see https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
311
328
  */
312
329
  function isArray(value) {
313
- if (Array.isArray(value)) {
314
- return true;
315
- }
316
- return false;
330
+ return Array.isArray(value);
317
331
  }
318
332
 
319
333
  /**
320
- * checks whether the value passed is a function
334
+ * Checks whether the value passed is a function
335
+ *
336
+ * This method is used in the library to have consistent names.
321
337
  *
322
338
  * you can call the method via the monster namespace `Monster.Types.isFunction()`.
323
339
  *
324
340
  * ```
325
341
  * <script type="module">
326
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
327
- * console.log(Monster.Types.isFunction(()=>{})) // ↦ true
328
- * console.log(Monster.Types.isFunction('2')) // ↦ false
329
- * console.log(Monster.Types.isFunction([])) // ↦ false
342
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/monster.js';
343
+ * Monster.Types.isFunction(()=>{}) // ↦ true
344
+ * Monster.Types.isFunction('2') // ↦ false
345
+ * Monster.Types.isFunction([]) // ↦ false
330
346
  * </script>
331
347
  * ```
332
348
  *
@@ -334,10 +350,10 @@ function isArray(value) {
334
350
  *
335
351
  * ```
336
352
  * <script type="module">
337
- * import {isFunction} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
338
- * console.log(isFunction(()=>{})) // ↦ true
339
- * console.log(isFunction('2')) // ↦ false
340
- * console.log(isFunction([])) // ↦ false
353
+ * import {isFunction} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/modules/types/is.js';
354
+ * isFunction(()=>{}) // ↦ true
355
+ * isFunction('2')) // ↦ false
356
+ * isFunction([])) // ↦ false
341
357
  * </script>
342
358
  * ```
343
359
  *
@@ -360,16 +376,18 @@ function isFunction(value) {
360
376
  }
361
377
 
362
378
  /**
363
- * checks whether the value passed is an integer
379
+ * Checks whether the value passed is an integer.
380
+ *
381
+ * This method is used in the library to have consistent names.
364
382
  *
365
- * you can call the method via the monster namespace `Monster.Types.isFunction()`.
383
+ * You can call the method via the monster namespace `Monster.Types.isFunction()`.
366
384
  *
367
385
  * ```
368
386
  * <script type="module">
369
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
370
- * console.log(Monster.Types.isInteger(()=>{})) // ↦ true
371
- * console.log(Monster.Types.isInteger('2')) // ↦ false
372
- * console.log(Monster.Types.isInteger(2)) // ↦ true
387
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/monster.js';
388
+ * Monster.Types.isInteger(()=>{}) // ↦ true
389
+ * Monster.Types.isInteger('2') // ↦ false
390
+ * Monster.Types.isInteger(2) // ↦ true
373
391
  * </script>
374
392
  * ```
375
393
  *
@@ -377,10 +395,10 @@ function isFunction(value) {
377
395
  *
378
396
  * ```
379
397
  * <script type="module">
380
- * import {isInteger} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/is.js';
381
- * console.log(isInteger(()=>{})) // ↦ true
382
- * console.log(isInteger('2')) // ↦ false
383
- * console.log(isInteger(2)) // ↦ true
398
+ * import {isInteger} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/modules/types/is.js';
399
+ * isInteger(()=>{}) // ↦ true
400
+ * isInteger('2')) // ↦ false
401
+ * isInteger(2)) // ↦ true
384
402
  * </script>
385
403
  * ```
386
404
  *
@@ -28,7 +28,7 @@ const internal = Symbol('internal');
28
28
  *
29
29
  * ```
30
30
  * <script type="module">
31
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/mediatype.js';
31
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/monster.js';
32
32
  * console.log(new Monster.Types.MediaType())
33
33
  * </script>
34
34
  * ```
@@ -37,7 +37,7 @@ const internal = Symbol('internal');
37
37
  *
38
38
  * ```
39
39
  * <script type="module">
40
- * import {MediaType} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/mediatype.js';
40
+ * import {MediaType} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/modules/types/mediatype.js';
41
41
  * console.log(new MediaType())
42
42
  * </script>
43
43
  * ```
@@ -137,7 +137,7 @@ class MediaType extends Base {
137
137
  *
138
138
  * ```
139
139
  * <script type="module">
140
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/dataurl.js';
140
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/monster.js';
141
141
  * console.log(Monster.Types.parseMediaType())
142
142
  * </script>
143
143
  * ```
@@ -146,7 +146,7 @@ class MediaType extends Base {
146
146
  *
147
147
  * ```
148
148
  * <script type="module">
149
- * import {parseMediaType} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/dataurl.js';
149
+ * import {parseMediaType} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/modules/types/dataurl.js';
150
150
  * console.log(parseMediaType())
151
151
  * </script>
152
152
  * ```
@@ -0,0 +1,210 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @author schukai GmbH
5
+ */
6
+
7
+
8
+ import {assignToNamespace, Monster} from '../namespace.js';
9
+ import {Base} from './base.js';
10
+ import {isPrimitive} from "./is.js";
11
+ import {NodeList} from './nodelist.js';
12
+ import {validateInstance} from './validate.js';
13
+
14
+ /**
15
+ * @private
16
+ * @type {symbol}
17
+ */
18
+ const internalValueSymbol = Symbol('internalData');
19
+
20
+ /**
21
+ * @private
22
+ * @type {symbol}
23
+ */
24
+ const treeStructureSymbol = Symbol('treeStructure');
25
+
26
+
27
+ /**
28
+ * You can create the instance via the monster namespace `new Monster.Types.Node()`.
29
+ *
30
+ * ```
31
+ * <script type="module">
32
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/monster.js';
33
+ * new Monster.Types.Node()
34
+ * </script>
35
+ * ```
36
+ *
37
+ * Alternatively, you can also integrate this function individually.
38
+ *
39
+ * ```
40
+ * <script type="module">
41
+ * import {Node} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.28.0/dist/modules/types/node.js';
42
+ * new Node()
43
+ * </script>
44
+ * ```
45
+ *
46
+ * @since 1.26.0
47
+ * @copyright schukai GmbH
48
+ * @memberOf Monster.Types
49
+ * @summary A Node Class
50
+ * @see https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Iteration_protocols
51
+ */
52
+ class Node extends Base {
53
+
54
+ /**
55
+ * @param {*} [value]
56
+ */
57
+ constructor(value) {
58
+ super();
59
+ this[internalValueSymbol] = value;
60
+
61
+ this[treeStructureSymbol] = {
62
+ parent: null,
63
+ childNodes: new NodeList,
64
+ level: 0
65
+ }
66
+
67
+ }
68
+
69
+ /**
70
+ * @property {*}
71
+ */
72
+ get value() {
73
+ return this[internalValueSymbol];
74
+ }
75
+
76
+ /**
77
+ * @property {*}
78
+ */
79
+ set value(value) {
80
+ this[internalValueSymbol] = value;
81
+ }
82
+
83
+ /**
84
+ * @property {Monster.Types.Node|null}
85
+ */
86
+ get parent() {
87
+ return this[treeStructureSymbol].parent;
88
+ }
89
+
90
+ /**
91
+ * @property {integer}
92
+ */
93
+ get level() {
94
+ return this[treeStructureSymbol].level;
95
+ }
96
+
97
+ /**
98
+ *
99
+ * @property {NodeList}
100
+ */
101
+ get childNodes() {
102
+ return this[treeStructureSymbol].childNodes;
103
+ }
104
+
105
+ /**
106
+ *
107
+ * @property {NodeList}
108
+ */
109
+ set childNodes(childNodes) {
110
+ this[treeStructureSymbol].childNodes = validateInstance(childNodes, NodeList);
111
+ setChildLevelAndParent.call(this, this, 1);
112
+ }
113
+
114
+ /**
115
+ * @return {Monster.Types.Node}
116
+ * @param {Node} node
117
+ */
118
+ appendChild(node) {
119
+ this[treeStructureSymbol].childNodes.add(validateInstance(node, Node));
120
+ node[treeStructureSymbol].parent = this;
121
+
122
+ node[treeStructureSymbol].level = this.level + 1;
123
+ setChildLevelAndParent.call(this, node, 1);
124
+ return this;
125
+ }
126
+
127
+ /**
128
+ * @return {Monster.Types.Node}
129
+ * @param {Node} node
130
+ */
131
+ removeChild(node) {
132
+ this[treeStructureSymbol].childNodes.remove(validateInstance(node, Node));
133
+ node[treeStructureSymbol].parent = null;
134
+
135
+ node[treeStructureSymbol].level = 0;
136
+ setChildLevelAndParent.call(this, node, -1);
137
+ return this;
138
+ }
139
+
140
+ /**
141
+ *
142
+ * @return {boolean}
143
+ */
144
+ hasChildNodes() {
145
+ return this[treeStructureSymbol].childNodes.length > 0;
146
+ }
147
+
148
+ /**
149
+ * @return {Monster.Types.Node}
150
+ * @param {Node} node
151
+ */
152
+ hasChild(node) {
153
+ return this[treeStructureSymbol].childNodes.has(validateInstance(node, Node));
154
+ }
155
+
156
+ /**
157
+ * @since 1.28.0
158
+ * @return {string}
159
+ */
160
+ toString() {
161
+
162
+ let parts = [];
163
+ if (this[internalValueSymbol]) {
164
+ let label = this[internalValueSymbol];
165
+ if (!isPrimitive(label)) label = JSON.stringify(this[internalValueSymbol])
166
+
167
+ parts.push( label);
168
+ }
169
+
170
+ if (!this.hasChildNodes()) {
171
+ return parts.join("\n");
172
+ }
173
+
174
+ let count = this.childNodes.length,
175
+ counter = 0;
176
+
177
+ for (const node of this.childNodes) {
178
+ counter++;
179
+ const prefix = (count === counter ? '└' : '├').padStart(2 * node.level, ' |');
180
+ parts.push(prefix + node.toString());
181
+ }
182
+
183
+ return parts.join("\n");
184
+ }
185
+
186
+ }
187
+
188
+ /**
189
+ * @private
190
+ * @param {Node} node
191
+ * @param {int} operand
192
+ * @return {setChildLevelAndParent}
193
+ */
194
+ function setChildLevelAndParent(node, operand) {
195
+ const self = this;
196
+
197
+ if (node !== this) {
198
+ node[treeStructureSymbol].parent = this
199
+ }
200
+
201
+ node[treeStructureSymbol].childNodes.forEach(function (child) {
202
+ child[treeStructureSymbol].parent = node;
203
+ child[treeStructureSymbol].level = node[treeStructureSymbol].level + operand;
204
+ setChildLevelAndParent.call(self, child, operand);
205
+ });
206
+ return this;
207
+ }
208
+
209
+ assignToNamespace('Monster.Types', Node);
210
+ export {Monster, Node}