@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.
- package/CHANGELOG +43 -0
- package/README.md +4 -4
- package/dist/modules/constants.js +1 -1
- package/dist/modules/constraints/abstract.js +1 -1
- package/dist/modules/constraints/abstractoperator.js +1 -1
- package/dist/modules/constraints/andoperator.js +1 -1
- package/dist/modules/constraints/invalid.js +1 -1
- package/dist/modules/constraints/isarray.js +1 -1
- package/dist/modules/constraints/isobject.js +1 -1
- package/dist/modules/constraints/namespace.js +1 -1
- package/dist/modules/constraints/oroperator.js +1 -1
- package/dist/modules/constraints/valid.js +1 -1
- package/dist/modules/data/buildmap.js +2 -2
- package/dist/modules/data/buildtree.js +2 -0
- package/dist/modules/data/datasource/namespace.js +1 -1
- package/dist/modules/data/datasource/restapi/writeerror.js +1 -1
- package/dist/modules/data/datasource/restapi.js +1 -1
- package/dist/modules/data/datasource/storage/localstorage.js +1 -1
- package/dist/modules/data/datasource/storage/namespace.js +1 -1
- package/dist/modules/data/datasource/storage/sessionstorage.js +1 -1
- package/dist/modules/data/datasource/storage.js +1 -1
- package/dist/modules/data/datasource.js +1 -1
- package/dist/modules/data/diff.js +1 -1
- package/dist/modules/data/extend.js +1 -1
- package/dist/modules/data/namespace.js +1 -1
- package/dist/modules/data/pathfinder.js +1 -1
- package/dist/modules/data/pipe.js +1 -1
- package/dist/modules/data/transformer.js +1 -1
- package/dist/modules/dom/assembler.js +1 -1
- package/dist/modules/dom/attributes.js +2 -2
- package/dist/modules/dom/constants.js +2 -2
- package/dist/modules/dom/customcontrol.js +1 -1
- package/dist/modules/dom/customelement.js +1 -1
- package/dist/modules/dom/events.js +1 -1
- package/dist/modules/dom/focusmanager.js +1 -1
- package/dist/modules/dom/locale.js +1 -1
- package/dist/modules/dom/namespace.js +1 -1
- package/dist/modules/dom/resource/data.js +1 -1
- package/dist/modules/dom/resource/link/stylesheet.js +1 -1
- package/dist/modules/dom/resource/link.js +1 -1
- package/dist/modules/dom/resource/script.js +1 -1
- package/dist/modules/dom/resource.js +1 -1
- package/dist/modules/dom/resourcemanager.js +1 -1
- package/dist/modules/dom/template.js +2 -2
- package/dist/modules/dom/theme.js +1 -1
- package/dist/modules/dom/updater.js +2 -2
- package/dist/modules/dom/util.js +1 -1
- package/dist/modules/dom/worker/factory.js +1 -1
- package/dist/modules/i18n/formatter.js +2 -0
- package/dist/modules/i18n/locale.js +1 -1
- package/dist/modules/i18n/namespace.js +1 -1
- package/dist/modules/i18n/provider.js +1 -1
- package/dist/modules/i18n/providers/fetch.js +1 -1
- package/dist/modules/i18n/providers/namespace.js +1 -1
- package/dist/modules/i18n/translations.js +1 -1
- package/dist/modules/logging/handler/console.js +1 -1
- package/dist/modules/logging/handler/namespace.js +1 -1
- package/dist/modules/logging/handler.js +1 -1
- package/dist/modules/logging/logentry.js +1 -1
- package/dist/modules/logging/logger.js +1 -1
- package/dist/modules/logging/namespace.js +1 -1
- package/dist/modules/math/namespace.js +1 -1
- package/dist/modules/math/random.js +1 -1
- package/dist/modules/monster.js +1 -1
- package/dist/modules/namespace.js +1 -1
- package/dist/modules/text/formatter.js +2 -2
- package/dist/modules/text/namespace.js +1 -1
- package/dist/modules/types/base.js +1 -1
- package/dist/modules/types/basewithoptions.js +1 -1
- package/dist/modules/types/binary.js +1 -1
- package/dist/modules/types/dataurl.js +1 -1
- package/dist/modules/types/global.js +1 -1
- package/dist/modules/types/id.js +1 -1
- package/dist/modules/types/is.js +2 -2
- package/dist/modules/types/mediatype.js +1 -1
- package/dist/modules/types/namespace.js +1 -1
- package/dist/modules/types/node.js +2 -0
- package/dist/modules/types/nodelist.js +2 -0
- package/dist/modules/types/noderecursiveiterator.js +2 -0
- package/dist/modules/types/observer.js +1 -1
- package/dist/modules/types/observerlist.js +1 -1
- package/dist/modules/types/proxyobserver.js +1 -1
- package/dist/modules/types/queue.js +1 -1
- package/dist/modules/types/randomid.js +1 -1
- package/dist/modules/types/regex.js +2 -0
- package/dist/modules/types/stack.js +1 -1
- package/dist/modules/types/tokenlist.js +1 -1
- package/dist/modules/types/typeof.js +1 -1
- package/dist/modules/types/uniquequeue.js +1 -1
- package/dist/modules/types/uuid.js +1 -1
- package/dist/modules/types/validate.js +1 -1
- package/dist/modules/types/version.js +2 -2
- package/dist/modules/util/clone.js +1 -1
- package/dist/modules/util/comparator.js +1 -1
- package/dist/modules/util/freeze.js +1 -1
- package/dist/modules/util/namespace.js +1 -1
- package/dist/modules/util/processing.js +1 -1
- package/dist/modules/util/trimspaces.js +1 -1
- package/dist/monster.dev.js +1181 -708
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +2 -2
- package/package.json +13 -2
- package/source/constraints/abstract.js +5 -0
- package/source/constraints/abstractoperator.js +5 -0
- package/source/constraints/andoperator.js +10 -5
- package/source/constraints/invalid.js +8 -3
- package/source/constraints/isarray.js +9 -4
- package/source/constraints/isobject.js +8 -3
- package/source/constraints/oroperator.js +10 -5
- package/source/constraints/valid.js +8 -3
- package/source/data/buildmap.js +27 -13
- package/source/data/buildtree.js +129 -0
- package/source/data/datasource/restapi.js +3 -3
- package/source/data/datasource/storage/localstorage.js +2 -2
- package/source/data/datasource/storage/sessionstorage.js +2 -2
- package/source/data/datasource/storage.js +3 -3
- package/source/data/datasource.js +3 -3
- package/source/data/diff.js +3 -3
- package/source/data/extend.js +2 -2
- package/source/data/pathfinder.js +4 -4
- package/source/data/pipe.js +3 -3
- package/source/data/transformer.js +3 -3
- package/source/dom/assembler.js +2 -2
- package/source/dom/attributes.js +111 -28
- package/source/dom/constants.js +17 -1
- package/source/dom/customcontrol.js +1 -1
- package/source/dom/customelement.js +1 -1
- package/source/dom/events.js +6 -7
- package/source/dom/focusmanager.js +6 -7
- package/source/dom/locale.js +8 -4
- package/source/dom/resource/data.js +2 -2
- package/source/dom/resource/link/stylesheet.js +2 -2
- package/source/dom/resource/link.js +2 -2
- package/source/dom/resource/script.js +2 -2
- package/source/dom/resource.js +2 -2
- package/source/dom/resourcemanager.js +2 -2
- package/source/dom/template.js +55 -15
- package/source/dom/theme.js +3 -3
- package/source/dom/updater.js +158 -98
- package/source/dom/util.js +6 -6
- package/source/dom/worker/factory.js +2 -2
- package/source/i18n/formatter.js +140 -0
- package/source/i18n/locale.js +6 -4
- package/source/i18n/provider.js +2 -2
- package/source/i18n/providers/fetch.js +18 -3
- package/source/i18n/translations.js +18 -9
- package/source/logging/handler/console.js +2 -2
- package/source/logging/handler.js +2 -2
- package/source/logging/logentry.js +2 -2
- package/source/logging/logger.js +2 -2
- package/source/math/random.js +2 -2
- package/source/namespace.js +1 -1
- package/source/text/formatter.js +190 -48
- package/source/types/base.js +2 -2
- package/source/types/basewithoptions.js +2 -2
- package/source/types/binary.js +4 -4
- package/source/types/dataurl.js +4 -4
- package/source/types/global.js +4 -4
- package/source/types/id.js +6 -3
- package/source/types/is.js +100 -82
- package/source/types/mediatype.js +4 -4
- package/source/types/node.js +210 -0
- package/source/types/nodelist.js +129 -0
- package/source/types/noderecursiveiterator.js +148 -0
- package/source/types/observer.js +3 -3
- package/source/types/observerlist.js +2 -2
- package/source/types/proxyobserver.js +5 -5
- package/source/types/queue.js +4 -4
- package/source/types/randomid.js +2 -2
- package/source/types/regex.js +49 -0
- package/source/types/stack.js +2 -2
- package/source/types/tokenlist.js +2 -2
- package/source/types/typeof.js +3 -3
- package/source/types/uniquequeue.js +2 -2
- package/source/types/uuid.js +2 -2
- package/source/types/validate.js +20 -20
- package/source/types/version.js +6 -6
- package/source/util/clone.js +2 -2
- package/source/util/comparator.js +3 -3
- package/source/util/freeze.js +2 -2
- package/source/util/processing.js +3 -3
- package/source/util/trimspaces.js +2 -2
- package/test/cases/data/buildtree.js +212 -0
- package/test/cases/dom/attributes.js +46 -19
- package/test/cases/dom/resource/link/stylesheet.js +1 -1
- package/test/cases/dom/template.js +72 -14
- package/test/cases/dom/updater.js +102 -75
- package/test/cases/i18n/formatter.js +66 -0
- package/test/cases/monster.js +1 -1
- package/test/cases/text/formatter.js +36 -5
- package/test/cases/types/node.js +252 -0
- package/test/cases/types/nodelist.js +71 -0
- package/test/cases/types/noderecursiveiterator.js +75 -0
- package/test/cases/types/regex.js +32 -0
- package/test/util/jsdom.js +0 -1
- package/test/web/import.js +6 -0
- package/test/web/monster-dev.html +3 -3
- package/test/web/monster.html +2 -2
- package/test/web/test.html +3 -3
- package/test/web/tests.js +3 -3
package/source/types/is.js
CHANGED
@@ -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.
|
17
|
-
*
|
18
|
-
*
|
19
|
-
*
|
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.
|
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.
|
55
|
-
*
|
56
|
-
*
|
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.
|
65
|
-
*
|
66
|
-
*
|
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.
|
100
|
-
*
|
101
|
-
*
|
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.
|
110
|
-
*
|
111
|
-
*
|
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.
|
133
|
-
*
|
134
|
-
*
|
135
|
-
*
|
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.
|
144
|
-
*
|
145
|
-
*
|
146
|
-
*
|
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
|
-
*
|
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
|
-
*
|
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.
|
173
|
-
*
|
174
|
-
*
|
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.
|
183
|
-
*
|
184
|
-
*
|
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
|
-
*
|
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
|
-
*
|
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.
|
209
|
-
*
|
210
|
-
*
|
211
|
-
*
|
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.
|
220
|
-
*
|
221
|
-
*
|
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
|
-
*
|
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.
|
251
|
-
*
|
252
|
-
*
|
253
|
-
*
|
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.
|
262
|
-
*
|
263
|
-
*
|
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
|
-
*
|
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.
|
291
|
-
*
|
292
|
-
*
|
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.
|
301
|
-
*
|
302
|
-
*
|
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
|
-
|
314
|
-
return true;
|
315
|
-
}
|
316
|
-
return false;
|
330
|
+
return Array.isArray(value);
|
317
331
|
}
|
318
332
|
|
319
333
|
/**
|
320
|
-
*
|
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.
|
327
|
-
*
|
328
|
-
*
|
329
|
-
*
|
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.
|
338
|
-
*
|
339
|
-
*
|
340
|
-
*
|
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
|
-
*
|
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
|
-
*
|
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.
|
370
|
-
*
|
371
|
-
*
|
372
|
-
*
|
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.
|
381
|
-
*
|
382
|
-
*
|
383
|
-
*
|
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.
|
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.
|
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.
|
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.
|
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}
|