@schukai/monster 1.25.0 → 1.26.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG +15 -0
- package/README.md +3 -3
- 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 +1 -1
- package/dist/modules/dom/constants.js +1 -1
- 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 +1 -1
- 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 +620 -361
- 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 +25 -9
- package/source/data/buildtree.js +95 -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 +24 -24
- package/source/dom/customcontrol.js +1 -1
- package/source/dom/customelement.js +1 -1
- package/source/dom/events.js +4 -4
- 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 +5 -5
- package/source/dom/theme.js +3 -3
- package/source/dom/updater.js +5 -5
- 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 +179 -0
- package/source/types/nodelist.js +125 -0
- package/source/types/noderecursiveiterator.js +126 -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 +149 -0
- package/test/cases/dom/attributes.js +18 -14
- package/test/cases/dom/resource/link/stylesheet.js +1 -1
- 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 +196 -0
- package/test/cases/types/nodelist.js +64 -0
- package/test/cases/types/noderecursiveiterator.js +54 -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 +2 -2
- 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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.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.26.0/dist/modules/types/dataurl.js';
|
150
150
|
* console.log(parseMediaType())
|
151
151
|
* </script>
|
152
152
|
* ```
|
@@ -0,0 +1,179 @@
|
|
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 {NodeList} from './nodelist.js';
|
11
|
+
import {validateInstance} from './validate.js';
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @private
|
15
|
+
* @type {symbol}
|
16
|
+
*/
|
17
|
+
const internalValueSymbol = Symbol('internalData');
|
18
|
+
|
19
|
+
/**
|
20
|
+
* @private
|
21
|
+
* @type {symbol}
|
22
|
+
*/
|
23
|
+
const treeStructureSymbol = Symbol('treeStructure');
|
24
|
+
|
25
|
+
|
26
|
+
/**
|
27
|
+
* You can create the instance via the monster namespace `new Monster.Types.Node()`.
|
28
|
+
*
|
29
|
+
* ```
|
30
|
+
* <script type="module">
|
31
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
32
|
+
* new Monster.Types.Node()
|
33
|
+
* </script>
|
34
|
+
* ```
|
35
|
+
*
|
36
|
+
* Alternatively, you can also integrate this function individually.
|
37
|
+
*
|
38
|
+
* ```
|
39
|
+
* <script type="module">
|
40
|
+
* import {Node} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/types/node.js';
|
41
|
+
* new Node()
|
42
|
+
* </script>
|
43
|
+
* ```
|
44
|
+
*
|
45
|
+
* @since 1.26.0
|
46
|
+
* @copyright schukai GmbH
|
47
|
+
* @memberOf Monster.Types
|
48
|
+
* @summary A Node Class
|
49
|
+
* @see https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Iteration_protocols
|
50
|
+
*/
|
51
|
+
class Node extends Base {
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @param {*} [value]
|
55
|
+
*/
|
56
|
+
constructor(value) {
|
57
|
+
super();
|
58
|
+
this[internalValueSymbol] = value;
|
59
|
+
|
60
|
+
this[treeStructureSymbol] = {
|
61
|
+
parent: null,
|
62
|
+
childNodes: new NodeList,
|
63
|
+
level: 0
|
64
|
+
}
|
65
|
+
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
* @property {*}
|
70
|
+
*/
|
71
|
+
get value() {
|
72
|
+
return this[internalValueSymbol];
|
73
|
+
}
|
74
|
+
|
75
|
+
/**
|
76
|
+
* @property {*}
|
77
|
+
*/
|
78
|
+
set value(value) {
|
79
|
+
this[internalValueSymbol] = value;
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
* @property {Monster.Types.Node|null}
|
84
|
+
*/
|
85
|
+
get parent() {
|
86
|
+
return this[treeStructureSymbol].parent;
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* @property {integer}
|
91
|
+
*/
|
92
|
+
get level() {
|
93
|
+
return this[treeStructureSymbol].level;
|
94
|
+
}
|
95
|
+
|
96
|
+
/**
|
97
|
+
*
|
98
|
+
* @property {NodeList}
|
99
|
+
*/
|
100
|
+
get childNodes() {
|
101
|
+
return this[treeStructureSymbol].childNodes;
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
*
|
106
|
+
* @property {NodeList}
|
107
|
+
*/
|
108
|
+
set childNodes(childNodes) {
|
109
|
+
this[treeStructureSymbol].childNodes = validateInstance(childNodes, NodeList);
|
110
|
+
setChildLevelAndParent.call(this, this, 1);
|
111
|
+
}
|
112
|
+
|
113
|
+
/**
|
114
|
+
* @return {Monster.Types.Node}
|
115
|
+
* @param {Node} node
|
116
|
+
*/
|
117
|
+
appendChild(node) {
|
118
|
+
this[treeStructureSymbol].childNodes.add(validateInstance(node, Node));
|
119
|
+
node[treeStructureSymbol].parent = this;
|
120
|
+
|
121
|
+
node[treeStructureSymbol].level = this.level + 1;
|
122
|
+
setChildLevelAndParent.call(this, node, 1);
|
123
|
+
return this;
|
124
|
+
}
|
125
|
+
|
126
|
+
/**
|
127
|
+
* @return {Monster.Types.Node}
|
128
|
+
* @param {Node} node
|
129
|
+
*/
|
130
|
+
removeChild(node) {
|
131
|
+
this[treeStructureSymbol].childNodes.remove(validateInstance(node, Node));
|
132
|
+
node[treeStructureSymbol].parent = null;
|
133
|
+
|
134
|
+
node[treeStructureSymbol].level = 0;
|
135
|
+
setChildLevelAndParent.call(this, node, -1);
|
136
|
+
return this;
|
137
|
+
}
|
138
|
+
|
139
|
+
/**
|
140
|
+
*
|
141
|
+
* @return {boolean}
|
142
|
+
*/
|
143
|
+
hasChildNodes() {
|
144
|
+
return this[treeStructureSymbol].childNodes.length > 0;
|
145
|
+
}
|
146
|
+
|
147
|
+
/**
|
148
|
+
* @return {Monster.Types.Node}
|
149
|
+
* @param {Node} node
|
150
|
+
*/
|
151
|
+
hasChild(node) {
|
152
|
+
return this[treeStructureSymbol].childNodes.has(validateInstance(node, Node));
|
153
|
+
}
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* @private
|
159
|
+
* @param {Node} node
|
160
|
+
* @param {int} operand
|
161
|
+
* @return {setChildLevelAndParent}
|
162
|
+
*/
|
163
|
+
function setChildLevelAndParent(node, operand) {
|
164
|
+
const self = this;
|
165
|
+
|
166
|
+
if (node !== this) {
|
167
|
+
node[treeStructureSymbol].parent = this
|
168
|
+
}
|
169
|
+
|
170
|
+
node[treeStructureSymbol].childNodes.forEach(function (child) {
|
171
|
+
child[treeStructureSymbol].parent = node;
|
172
|
+
child[treeStructureSymbol].level = node[treeStructureSymbol].level + operand;
|
173
|
+
setChildLevelAndParent.call(self, child, operand);
|
174
|
+
});
|
175
|
+
return this;
|
176
|
+
}
|
177
|
+
|
178
|
+
assignToNamespace('Monster.Types', Node);
|
179
|
+
export {Monster, Node}
|