@schukai/monster 1.12.0 → 1.15.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG +40 -1
- package/README.md +5 -5
- package/dist/modules/constants.js +2 -0
- package/dist/modules/constraints/abstract.js +2 -2
- package/dist/modules/constraints/abstractoperator.js +2 -2
- package/dist/modules/constraints/andoperator.js +2 -2
- package/dist/modules/constraints/invalid.js +2 -2
- package/dist/modules/constraints/isarray.js +2 -2
- package/dist/modules/constraints/isobject.js +2 -2
- package/dist/modules/constraints/namespace.js +1 -1
- package/dist/modules/constraints/oroperator.js +2 -2
- package/dist/modules/constraints/valid.js +2 -2
- package/dist/modules/data/buildmap.js +2 -2
- package/dist/modules/data/diff.js +2 -2
- package/dist/modules/data/extend.js +2 -2
- package/dist/modules/data/namespace.js +1 -1
- package/dist/modules/data/pathfinder.js +2 -2
- package/dist/modules/data/pipe.js +2 -2
- package/dist/modules/data/transformer.js +2 -2
- package/dist/modules/dom/assembler.js +2 -2
- package/dist/modules/dom/attributes.js +2 -2
- package/dist/modules/dom/constants.js +2 -2
- package/dist/modules/dom/customcontrol.js +2 -0
- package/dist/modules/dom/customelement.js +2 -2
- package/dist/modules/dom/events.js +2 -2
- package/dist/modules/dom/locale.js +2 -0
- package/dist/modules/dom/namespace.js +1 -1
- package/dist/modules/dom/template.js +2 -2
- package/dist/modules/dom/theme.js +2 -2
- package/dist/modules/dom/updater.js +2 -2
- package/dist/modules/dom/util.js +2 -2
- package/dist/modules/i18n/locale.js +2 -0
- package/dist/modules/i18n/namespace.js +2 -0
- package/dist/modules/i18n/provider.js +2 -0
- package/dist/modules/i18n/providers/fetch.js +2 -0
- package/dist/modules/i18n/providers/namespace.js +2 -0
- package/dist/modules/i18n/translations.js +2 -0
- package/dist/modules/logging/handler/console.js +2 -2
- package/dist/modules/logging/handler/namespace.js +1 -1
- package/dist/modules/logging/handler.js +2 -2
- package/dist/modules/logging/logentry.js +2 -2
- package/dist/modules/logging/logger.js +2 -2
- package/dist/modules/logging/namespace.js +1 -1
- package/dist/modules/math/namespace.js +1 -1
- package/dist/modules/math/random.js +2 -2
- package/dist/modules/monster.js +2 -2
- 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 +2 -2
- package/dist/modules/types/basewithoptions.js +2 -0
- package/dist/modules/types/global.js +2 -2
- package/dist/modules/types/id.js +2 -2
- package/dist/modules/types/is.js +2 -2
- package/dist/modules/types/namespace.js +1 -1
- package/dist/modules/types/observer.js +2 -2
- package/dist/modules/types/observerlist.js +2 -2
- package/dist/modules/types/proxyobserver.js +2 -2
- package/dist/modules/types/queue.js +2 -2
- package/dist/modules/types/randomid.js +2 -2
- package/dist/modules/types/stack.js +2 -2
- package/dist/modules/types/tokenlist.js +2 -2
- package/dist/modules/types/typeof.js +2 -2
- package/dist/modules/types/uniquequeue.js +2 -2
- package/dist/modules/types/validate.js +2 -2
- package/dist/modules/types/version.js +2 -2
- package/dist/modules/util/clone.js +2 -2
- package/dist/modules/util/comparator.js +2 -2
- package/dist/modules/util/freeze.js +2 -2
- package/dist/modules/util/namespace.js +1 -1
- package/dist/monster.dev.js +8692 -6669
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +3 -3
- package/package.json +1 -1
- package/source/constants.js +22 -0
- package/source/constraints/abstract.js +2 -2
- package/source/constraints/abstractoperator.js +3 -3
- package/source/constraints/andoperator.js +7 -7
- package/source/constraints/invalid.js +6 -6
- package/source/constraints/isarray.js +6 -6
- package/source/constraints/isobject.js +6 -6
- package/source/constraints/namespace.js +2 -0
- package/source/constraints/oroperator.js +8 -8
- package/source/constraints/valid.js +6 -6
- package/source/data/buildmap.js +15 -15
- package/source/data/diff.js +6 -6
- package/source/data/extend.js +55 -13
- package/source/data/namespace.js +2 -0
- package/source/data/pathfinder.js +6 -7
- package/source/data/pipe.js +5 -5
- package/source/data/transformer.js +6 -6
- package/source/dom/assembler.js +5 -5
- package/source/dom/attributes.js +89 -45
- package/source/dom/constants.js +8 -9
- package/source/dom/customcontrol.js +301 -0
- package/source/dom/customelement.js +149 -31
- package/source/dom/events.js +58 -8
- package/source/dom/locale.js +59 -0
- package/source/dom/namespace.js +2 -0
- package/source/dom/template.js +7 -7
- package/source/dom/theme.js +6 -6
- package/source/dom/updater.js +38 -11
- package/source/dom/util.js +10 -10
- package/source/i18n/locale.js +322 -0
- package/source/i18n/namespace.js +15 -0
- package/source/i18n/provider.js +58 -0
- package/source/i18n/providers/fetch.js +121 -0
- package/source/i18n/providers/namespace.js +15 -0
- package/source/i18n/translations.js +209 -0
- package/source/logging/handler/console.js +4 -4
- package/source/logging/handler.js +4 -4
- package/source/logging/logentry.js +4 -4
- package/source/logging/logger.js +4 -4
- package/source/logging/namespace.js +2 -0
- package/source/math/namespace.js +2 -0
- package/source/math/random.js +5 -5
- package/source/monster.js +26 -16
- package/source/namespace.js +10 -8
- package/source/text/formatter.js +4 -5
- package/source/text/namespace.js +1 -1
- package/source/types/base.js +4 -7
- package/source/types/basewithoptions.js +97 -0
- package/source/types/global.js +6 -6
- package/source/types/id.js +6 -6
- package/source/types/is.js +22 -22
- package/source/types/namespace.js +3 -1
- package/source/types/observer.js +5 -5
- package/source/types/observerlist.js +4 -4
- package/source/types/proxyobserver.js +32 -26
- package/source/types/queue.js +13 -7
- package/source/types/randomid.js +5 -5
- package/source/types/stack.js +11 -4
- package/source/types/tokenlist.js +4 -4
- package/source/types/typeof.js +5 -5
- package/source/types/uniquequeue.js +11 -4
- package/source/types/validate.js +22 -22
- package/source/types/version.js +9 -9
- package/source/util/clone.js +4 -4
- package/source/util/comparator.js +6 -6
- package/source/util/freeze.js +4 -4
- package/source/util/namespace.js +2 -0
- package/test/cases/data/extend.js +66 -13
- package/test/cases/dom/attributes.js +56 -1
- package/test/cases/dom/customcontrol.js +264 -0
- package/test/cases/dom/customelement.js +112 -51
- package/test/cases/dom/events.js +32 -14
- package/test/cases/dom/locale.js +44 -0
- package/test/cases/i18n/locale.js +80 -0
- package/test/cases/i18n/provider.js +15 -0
- package/test/cases/i18n/providers/fetch.js +65 -0
- package/test/cases/i18n/translations.js +57 -0
- package/test/cases/monster.js +3 -1
- package/test/cases/{util → text}/formatter.js +2 -0
- package/test/cases/types/basewithoptions.js +25 -0
- package/test/cases/types/proxyobserver.js +9 -0
- package/test/cases/{text → util}/clone.js +0 -0
- package/test/cases/{text → util}/comparator.js +0 -0
- package/test/util/jsdom.js +4 -0
- package/test/web/import.js +10 -3
- package/test/web/monster-dev.html +3 -3
- package/test/web/monster.html +3 -3
- package/test/web/test.html +3 -3
- package/test/web/tests.js +3 -3
@@ -0,0 +1,97 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @author schukai GmbH
|
5
|
+
*/
|
6
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
7
|
+
import {Pathfinder} from "../data/pathfinder.js";
|
8
|
+
import {Base} from "./base.js";
|
9
|
+
import {validateObject} from "./validate.js";
|
10
|
+
import {PROPERTY_KEY_INTERNALDATA} from "../constants.js";
|
11
|
+
import {extend} from "../data/extend.js";
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @private
|
15
|
+
* @type {symbol}
|
16
|
+
*/
|
17
|
+
const optionsSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
18
|
+
|
19
|
+
/**
|
20
|
+
* This is the base class with options from which some monster classes are derived.
|
21
|
+
*
|
22
|
+
* You can call the method via the monster namespace `new Monster.Types.BaseWithOptions()`.
|
23
|
+
*
|
24
|
+
* ```
|
25
|
+
* <script type="module">
|
26
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/basewithoptions.js';
|
27
|
+
* console.log(new Monster.Types.BaseWithOptions())
|
28
|
+
* </script>
|
29
|
+
* ```
|
30
|
+
*
|
31
|
+
* Alternatively, you can also integrate this function individually.
|
32
|
+
*
|
33
|
+
* ```
|
34
|
+
* <script type="module">
|
35
|
+
* import {BaseWithOptions} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/basewithoptions.js';
|
36
|
+
* console.log(new BaseWithOptions())
|
37
|
+
* </script>
|
38
|
+
* ```
|
39
|
+
*
|
40
|
+
* The class was formerly called Object.
|
41
|
+
*
|
42
|
+
* @since 1.13.0
|
43
|
+
* @copyright schukai GmbH
|
44
|
+
* @memberOf Monster/Types
|
45
|
+
*/
|
46
|
+
class BaseWithOptions extends Base {
|
47
|
+
|
48
|
+
/**
|
49
|
+
*
|
50
|
+
* @param {object} options
|
51
|
+
*/
|
52
|
+
constructor(options) {
|
53
|
+
super();
|
54
|
+
|
55
|
+
if (options === undefined) {
|
56
|
+
options = {};
|
57
|
+
}
|
58
|
+
|
59
|
+
this[optionsSymbol] = extend({}, this.defaults, validateObject(options));
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
/**
|
64
|
+
* can be overridden by child class values
|
65
|
+
*
|
66
|
+
* @return {object}
|
67
|
+
*/
|
68
|
+
get defaults() {
|
69
|
+
return {}
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* nested options can be specified by path `a.b.c`
|
74
|
+
*
|
75
|
+
* @param {string} path
|
76
|
+
* @param {*} defaultValue
|
77
|
+
* @return {*}
|
78
|
+
* @since 1.10.0
|
79
|
+
*/
|
80
|
+
getOption(path, defaultValue) {
|
81
|
+
let value;
|
82
|
+
|
83
|
+
try {
|
84
|
+
value = new Pathfinder(this[optionsSymbol]).getVia(path);
|
85
|
+
} catch (e) {
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
if (value === undefined) return defaultValue;
|
90
|
+
return value;
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
}
|
95
|
+
|
96
|
+
assignToNamespace('Monster.Types', BaseWithOptions);
|
97
|
+
export {Monster, BaseWithOptions}
|
package/source/types/global.js
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
* @author schukai GmbH
|
5
5
|
*/
|
6
6
|
|
7
|
-
import {Monster} from '../namespace.js';
|
7
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
8
8
|
import {validateFunction, validateString, validateObject} from "./validate.js";
|
9
9
|
|
10
10
|
/**
|
@@ -78,7 +78,7 @@ function getGlobal() {
|
|
78
78
|
*
|
79
79
|
* ```
|
80
80
|
* <script type="module">
|
81
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
81
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/global.js';
|
82
82
|
* console.log(Monster.Types.getGlobalObject('document')) // ↦ { }
|
83
83
|
* </script>
|
84
84
|
* ```
|
@@ -87,7 +87,7 @@ function getGlobal() {
|
|
87
87
|
*
|
88
88
|
* ```
|
89
89
|
* <script type="module">
|
90
|
-
* import {getGlobalObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
90
|
+
* import {getGlobalObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/global.js';
|
91
91
|
* console.log(getGlobalObject('document')) // ↦ { }
|
92
92
|
* </script>
|
93
93
|
* ```
|
@@ -115,7 +115,7 @@ function getGlobalObject(name) {
|
|
115
115
|
*
|
116
116
|
* ```
|
117
117
|
* <script type="module">
|
118
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
118
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/global.js';
|
119
119
|
* console.log(Monster.Types.getGlobalFunction('parseInt')) // ↦ f parseInt() { }
|
120
120
|
* </script>
|
121
121
|
* ```
|
@@ -124,7 +124,7 @@ function getGlobalObject(name) {
|
|
124
124
|
*
|
125
125
|
* ```
|
126
126
|
* <script type="module">
|
127
|
-
* import {getGlobalFunction} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
127
|
+
* import {getGlobalFunction} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/global.js';
|
128
128
|
* console.log(getGlobalFunction('parseInt')) // ↦ f parseInt() { }
|
129
129
|
* </script>
|
130
130
|
* ```
|
@@ -146,5 +146,5 @@ function getGlobalFunction(name) {
|
|
146
146
|
}
|
147
147
|
|
148
148
|
|
149
|
-
|
149
|
+
assignToNamespace('Monster.Types', getGlobal, getGlobalObject, getGlobalFunction);
|
150
150
|
export {Monster, getGlobal, getGlobalObject, getGlobalFunction}
|
package/source/types/id.js
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
/**
|
4
4
|
* @author schukai GmbH
|
5
|
-
*/
|
6
|
-
|
7
|
-
import {
|
5
|
+
*/
|
6
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
7
|
+
import { Base} from './base.js';
|
8
8
|
import {validateString} from "./validate.js";
|
9
9
|
|
10
10
|
/**
|
@@ -24,7 +24,7 @@ let internalCounter = new Map;
|
|
24
24
|
*
|
25
25
|
* ```
|
26
26
|
* <script type="module">
|
27
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
27
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/id.js';
|
28
28
|
* console.log(new Monster.Types.ID())
|
29
29
|
* </script>
|
30
30
|
* ```
|
@@ -33,7 +33,7 @@ let internalCounter = new Map;
|
|
33
33
|
*
|
34
34
|
* ```
|
35
35
|
* <script type="module">
|
36
|
-
* import {ID} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
36
|
+
* import {ID} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/id.js';
|
37
37
|
* console.log(new ID())
|
38
38
|
* </script>
|
39
39
|
* ```
|
@@ -77,5 +77,5 @@ class ID extends Base {
|
|
77
77
|
|
78
78
|
}
|
79
79
|
|
80
|
-
|
80
|
+
assignToNamespace('Monster.Types', ID);
|
81
81
|
export {Monster, ID}
|
package/source/types/is.js
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
* @author schukai GmbH
|
5
5
|
*/
|
6
6
|
|
7
|
-
import {Monster} from '../namespace.js';
|
7
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
8
8
|
|
9
9
|
/**
|
10
10
|
* With this function you can check if a value is iterable
|
@@ -13,7 +13,7 @@ import {Monster} from '../namespace.js';
|
|
13
13
|
*
|
14
14
|
* ```
|
15
15
|
* <script type="module">
|
16
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
16
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
17
17
|
* console.log(Monster.Types.isIterable(null)) // ↦ false
|
18
18
|
* console.log(Monster.Types.isIterable('hello')) // ↦ true
|
19
19
|
* console.log(Monster.Types.isIterable([])) // ↦ true
|
@@ -24,7 +24,7 @@ import {Monster} from '../namespace.js';
|
|
24
24
|
*
|
25
25
|
* ```
|
26
26
|
* <script type="module">
|
27
|
-
* import {isIterable} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
27
|
+
* import {isIterable} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
28
28
|
* console.log(isIterable(null)) // ↦ false
|
29
29
|
* console.log(isIterable('hello')) // ↦ true
|
30
30
|
* console.log(isIterable([])) // ↦ true
|
@@ -51,7 +51,7 @@ function isIterable(value) {
|
|
51
51
|
*
|
52
52
|
* ```
|
53
53
|
* <script type="module">
|
54
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
54
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
55
55
|
* console.log(Monster.Types.isPrimitive('2')) // ↦ false
|
56
56
|
* console.log(Monster.Types.isPrimitive([])) // ↦ true
|
57
57
|
* </script>
|
@@ -61,7 +61,7 @@ function isIterable(value) {
|
|
61
61
|
*
|
62
62
|
* ```
|
63
63
|
* <script type="module">
|
64
|
-
* import {isPrimitive} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
64
|
+
* import {isPrimitive} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
65
65
|
* console.log(isPrimitive('2')) // ↦ true
|
66
66
|
* console.log(isPrimitive([])) // ↦ false
|
67
67
|
* </script>
|
@@ -96,7 +96,7 @@ function isPrimitive(value) {
|
|
96
96
|
*
|
97
97
|
* ```
|
98
98
|
* <script type="module">
|
99
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
99
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
100
100
|
* console.log(Monster.Types.isSymbol('2')) // ↦ false
|
101
101
|
* console.log(Monster.Types.isSymbol(Symbol('test')) // ↦ true
|
102
102
|
* </script>
|
@@ -106,7 +106,7 @@ function isPrimitive(value) {
|
|
106
106
|
*
|
107
107
|
* ```
|
108
108
|
* <script type="module">
|
109
|
-
* import {isSymbol} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
109
|
+
* import {isSymbol} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
110
110
|
* console.log(isSymbol(Symbol('a'))) // ↦ true
|
111
111
|
* console.log(isSymbol([]) // ↦ false
|
112
112
|
* </script>
|
@@ -129,7 +129,7 @@ function isSymbol(value) {
|
|
129
129
|
*
|
130
130
|
* ```
|
131
131
|
* <script type="module">
|
132
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
132
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
133
133
|
* console.log(Monster.Types.isBoolean('2')) // ↦ false
|
134
134
|
* console.log(Monster.Types.isBoolean([])) // ↦ false
|
135
135
|
* console.log(Monster.Types.isBoolean(true)) // ↦ true
|
@@ -140,7 +140,7 @@ function isSymbol(value) {
|
|
140
140
|
*
|
141
141
|
* ```
|
142
142
|
* <script type="module">
|
143
|
-
* import {isBoolean} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
143
|
+
* import {isBoolean} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
144
144
|
* console.log(isBoolean('2')) // ↦ false
|
145
145
|
* console.log(isBoolean([])) // ↦ false
|
146
146
|
* console.log(isBoolean(2>4)) // ↦ true
|
@@ -169,7 +169,7 @@ function isBoolean(value) {
|
|
169
169
|
*
|
170
170
|
* ```
|
171
171
|
* <script type="module">
|
172
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
172
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
173
173
|
* console.log(Monster.Types.isString('2')) // ↦ true
|
174
174
|
* console.log(Monster.Types.isString([])) // ↦ false
|
175
175
|
* </script>
|
@@ -179,7 +179,7 @@ function isBoolean(value) {
|
|
179
179
|
*
|
180
180
|
* ```
|
181
181
|
* <script type="module">
|
182
|
-
* import {isString} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
182
|
+
* import {isString} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
183
183
|
* console.log(isString('2')) // ↦ true
|
184
184
|
* console.log(isString([])) // ↦ false
|
185
185
|
* </script>
|
@@ -205,7 +205,7 @@ function isString(value) {
|
|
205
205
|
*
|
206
206
|
* ```
|
207
207
|
* <script type="module">
|
208
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
208
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
209
209
|
* console.log(Monster.Types.isObject('2')) // ↦ false
|
210
210
|
* console.log(Monster.Types.isObject([])) // ↦ false
|
211
211
|
* console.log(Monster.Types.isObject({})) // ↦ true
|
@@ -216,7 +216,7 @@ function isString(value) {
|
|
216
216
|
*
|
217
217
|
* ```
|
218
218
|
* <script type="module">
|
219
|
-
* import {isObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
219
|
+
* import {isObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
220
220
|
* console.log(isObject('2')) // ↦ false
|
221
221
|
* console.log(isObject([])) // ↦ false
|
222
222
|
* </script>
|
@@ -247,7 +247,7 @@ function isObject(value) {
|
|
247
247
|
*
|
248
248
|
* ```
|
249
249
|
* <script type="module">
|
250
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
250
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
251
251
|
* console.log(Monster.Types.isInstance('2')) // ↦ false
|
252
252
|
* console.log(Monster.Types.isInstance([])) // ↦ false
|
253
253
|
* console.log(Monster.Types.isInstance({})) // ↦ true
|
@@ -258,7 +258,7 @@ function isObject(value) {
|
|
258
258
|
*
|
259
259
|
* ```
|
260
260
|
* <script type="module">
|
261
|
-
* import {isInstance} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
261
|
+
* import {isInstance} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
262
262
|
* console.log(isInstance('2')) // ↦ false
|
263
263
|
* console.log(isInstance([])) // ↦ false
|
264
264
|
* </script>
|
@@ -287,7 +287,7 @@ function isInstance(value, instance) {
|
|
287
287
|
*
|
288
288
|
* ```
|
289
289
|
* <script type="module">
|
290
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
290
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
291
291
|
* console.log(Monster.Types.isArray('2')) // ↦ false
|
292
292
|
* console.log(Monster.Types.isArray([])) // ↦ true
|
293
293
|
* </script>
|
@@ -297,7 +297,7 @@ function isInstance(value, instance) {
|
|
297
297
|
*
|
298
298
|
* ```
|
299
299
|
* <script type="module">
|
300
|
-
* import {isArray} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
300
|
+
* import {isArray} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
301
301
|
* console.log(isArray('2')) // ↦ false
|
302
302
|
* console.log(isArray([])) // ↦ true
|
303
303
|
* </script>
|
@@ -323,7 +323,7 @@ function isArray(value) {
|
|
323
323
|
*
|
324
324
|
* ```
|
325
325
|
* <script type="module">
|
326
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
326
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
327
327
|
* console.log(Monster.Types.isFunction(()=>{})) // ↦ true
|
328
328
|
* console.log(Monster.Types.isFunction('2')) // ↦ false
|
329
329
|
* console.log(Monster.Types.isFunction([])) // ↦ false
|
@@ -334,7 +334,7 @@ function isArray(value) {
|
|
334
334
|
*
|
335
335
|
* ```
|
336
336
|
* <script type="module">
|
337
|
-
* import {isFunction} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
337
|
+
* import {isFunction} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
338
338
|
* console.log(isFunction(()=>{})) // ↦ true
|
339
339
|
* console.log(isFunction('2')) // ↦ false
|
340
340
|
* console.log(isFunction([])) // ↦ false
|
@@ -366,7 +366,7 @@ function isFunction(value) {
|
|
366
366
|
*
|
367
367
|
* ```
|
368
368
|
* <script type="module">
|
369
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
369
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
370
370
|
* console.log(Monster.Types.isInteger(()=>{})) // ↦ true
|
371
371
|
* console.log(Monster.Types.isInteger('2')) // ↦ false
|
372
372
|
* console.log(Monster.Types.isInteger(2)) // ↦ true
|
@@ -377,7 +377,7 @@ function isFunction(value) {
|
|
377
377
|
*
|
378
378
|
* ```
|
379
379
|
* <script type="module">
|
380
|
-
* import {isInteger} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
380
|
+
* import {isInteger} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
381
381
|
* console.log(isInteger(()=>{})) // ↦ true
|
382
382
|
* console.log(isInteger('2')) // ↦ false
|
383
383
|
* console.log(isInteger(2)) // ↦ true
|
@@ -395,7 +395,7 @@ function isInteger(value) {
|
|
395
395
|
}
|
396
396
|
|
397
397
|
|
398
|
-
|
398
|
+
assignToNamespace('Monster.Types', isPrimitive, isBoolean, isString, isObject, isArray, isFunction, isIterable, isInteger, isSymbol);
|
399
399
|
export {
|
400
400
|
Monster,
|
401
401
|
isPrimitive,
|
package/source/types/observer.js
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
* @author schukai GmbH
|
5
5
|
*/
|
6
6
|
|
7
|
-
import {Monster} from '../namespace.js';
|
7
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
8
8
|
import {TokenList} from './tokenlist.js';
|
9
9
|
import {isObject} from './is.js';
|
10
10
|
import {Base} from './base.js';
|
@@ -17,7 +17,7 @@ import {UniqueQueue} from './uniquequeue.js';
|
|
17
17
|
*
|
18
18
|
* ```
|
19
19
|
* <script type="module">
|
20
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
20
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/observer.js';
|
21
21
|
* console.log(new Monster.Types.Observer())
|
22
22
|
* </script>
|
23
23
|
* ```
|
@@ -26,7 +26,7 @@ import {UniqueQueue} from './uniquequeue.js';
|
|
26
26
|
*
|
27
27
|
* ```
|
28
28
|
* <script type="module">
|
29
|
-
* import {Observer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
29
|
+
* import {Observer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/observer.js';
|
30
30
|
* console.log(new Observer())
|
31
31
|
* </script>
|
32
32
|
* ```
|
@@ -60,7 +60,7 @@ import {UniqueQueue} from './uniquequeue.js';
|
|
60
60
|
*
|
61
61
|
* @example
|
62
62
|
*
|
63
|
-
* import {Observer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
63
|
+
* import {Observer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/observer.js';
|
64
64
|
*
|
65
65
|
* const observer = new Observer(function(a, b, c) {
|
66
66
|
* console.log(this, a, b, c); // ↦ "a", 2, true
|
@@ -177,7 +177,7 @@ class Observer extends Base {
|
|
177
177
|
|
178
178
|
}
|
179
179
|
|
180
|
-
|
180
|
+
assignToNamespace('Monster.Types', Observer);
|
181
181
|
export {Monster, Observer}
|
182
182
|
|
183
183
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
* @author schukai GmbH
|
5
5
|
*/
|
6
6
|
|
7
|
-
import {Monster} from '../namespace.js';
|
7
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
8
8
|
import {Base} from './base.js';
|
9
9
|
import {Observer} from "./observer.js";
|
10
10
|
import {validateInstance} from "./validate.js";
|
@@ -16,7 +16,7 @@ import {validateInstance} from "./validate.js";
|
|
16
16
|
*
|
17
17
|
* ```
|
18
18
|
* <script type="module">
|
19
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
19
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/observerlist.js';
|
20
20
|
* console.log(new Monster.Types.ObserverList())
|
21
21
|
* console.log(new Monster.Types.ObserverList())
|
22
22
|
* </script>
|
@@ -26,7 +26,7 @@ import {validateInstance} from "./validate.js";
|
|
26
26
|
*
|
27
27
|
* ```
|
28
28
|
* <script type="module">
|
29
|
-
* import {ObserverList} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
29
|
+
* import {ObserverList} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/observerlist.js';
|
30
30
|
* console.log(ObserverList())
|
31
31
|
* console.log(ObserverList())
|
32
32
|
* </script>
|
@@ -114,5 +114,5 @@ class ObserverList extends Base {
|
|
114
114
|
|
115
115
|
}
|
116
116
|
|
117
|
-
|
117
|
+
assignToNamespace('Monster.Types', ObserverList);
|
118
118
|
export {Monster, ObserverList}
|
@@ -3,8 +3,8 @@
|
|
3
3
|
/**
|
4
4
|
* @author schukai GmbH
|
5
5
|
*/
|
6
|
-
|
7
|
-
import {
|
6
|
+
import {Monster, assignToNamespace} from '../namespace.js';
|
7
|
+
import { Base} from './base.js';
|
8
8
|
import {validateObject} from "./validate.js";
|
9
9
|
import {ObserverList} from "./observerlist.js";
|
10
10
|
import {Observer} from "./observer.js";
|
@@ -13,20 +13,20 @@ import {isObject, isArray, isPrimitive} from "./is.js";
|
|
13
13
|
/**
|
14
14
|
* An observer manages a callback function
|
15
15
|
*
|
16
|
-
* You can call the
|
16
|
+
* You can call create the class via the monster namespace `new Monster.Types.ProxyObserver()`.
|
17
17
|
*
|
18
18
|
* ```
|
19
19
|
* <script type="module">
|
20
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
20
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/proxyobserver.js';
|
21
21
|
* console.log(new Monster.Types.ProxyObserver())
|
22
22
|
* </script>
|
23
23
|
* ```
|
24
24
|
*
|
25
|
-
* Alternatively, you can also integrate this
|
25
|
+
* Alternatively, you can also integrate this class individually.
|
26
26
|
*
|
27
27
|
* ```
|
28
28
|
* <script type="module">
|
29
|
-
* import {ProxyObserver} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
29
|
+
* import {ProxyObserver} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/proxyobserver.js';
|
30
30
|
* console.log(new ProxyObserver())
|
31
31
|
* </script>
|
32
32
|
* ```
|
@@ -37,9 +37,9 @@ import {isObject, isArray, isPrimitive} from "./is.js";
|
|
37
37
|
*
|
38
38
|
* @example
|
39
39
|
*
|
40
|
-
* import {ProxyObserver} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
41
|
-
* import {Observer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
42
|
-
* import {isObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
40
|
+
* import {ProxyObserver} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/proxyobserver.js';
|
41
|
+
* import {Observer} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/observer.js';
|
42
|
+
* import {isObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.0/dist/modules/types/is.js';
|
43
43
|
*
|
44
44
|
* const o = new Observer(function () {
|
45
45
|
* if (isObject(this) && this instanceof ProxyObserver) {
|
@@ -76,13 +76,16 @@ class ProxyObserver extends Base {
|
|
76
76
|
*/
|
77
77
|
constructor(object) {
|
78
78
|
super();
|
79
|
-
|
80
|
-
this.realSubject = object
|
79
|
+
|
80
|
+
this.realSubject = validateObject(object);
|
81
81
|
this.subject = new Proxy(object, getHandler.call(this));
|
82
82
|
|
83
83
|
this.objectMap = new WeakMap();
|
84
84
|
this.objectMap.set(this.realSubject, this.subject);
|
85
85
|
|
86
|
+
this.proxyMap = new WeakMap();
|
87
|
+
this.proxyMap.set(this.subject, this.realSubject);
|
88
|
+
|
86
89
|
this.observers = new ObserverList;
|
87
90
|
}
|
88
91
|
|
@@ -139,7 +142,7 @@ class ProxyObserver extends Base {
|
|
139
142
|
|
140
143
|
/**
|
141
144
|
* @param {Observer} observer
|
142
|
-
* @returns {
|
145
|
+
* @returns {boolean}
|
143
146
|
*/
|
144
147
|
containsObserver(observer) {
|
145
148
|
return this.observers.contains(observer)
|
@@ -147,7 +150,7 @@ class ProxyObserver extends Base {
|
|
147
150
|
|
148
151
|
}
|
149
152
|
|
150
|
-
|
153
|
+
assignToNamespace('Monster.Types', ProxyObserver);
|
151
154
|
export {Monster, ProxyObserver}
|
152
155
|
|
153
156
|
/**
|
@@ -180,9 +183,12 @@ function getHandler() {
|
|
180
183
|
if ((isArray(value) || isObject(value))) {
|
181
184
|
if (proxy.objectMap.has(value)) {
|
182
185
|
return proxy.objectMap.get(value);
|
186
|
+
} else if (proxy.proxyMap.has(value)) {
|
187
|
+
return value;
|
183
188
|
} else {
|
184
189
|
let p = new Proxy(value, handler);
|
185
190
|
proxy.objectMap.set(value, p);
|
191
|
+
proxy.proxyMap.set(p, value);
|
186
192
|
return p;
|
187
193
|
}
|
188
194
|
|
@@ -195,18 +201,24 @@ function getHandler() {
|
|
195
201
|
// https://262.ecma-international.org/9.0/#sec-proxy-object-internal-methods-and-internal-slots-set-p-v-receiver
|
196
202
|
set: function (target, key, value, receiver) {
|
197
203
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
204
|
+
if(proxy.proxyMap.has(value)) {
|
205
|
+
value= proxy.proxyMap.get(value);
|
206
|
+
}
|
207
|
+
|
208
|
+
if(proxy.proxyMap.has(target)) {
|
209
|
+
target= proxy.proxyMap.get(target);
|
210
|
+
}
|
211
|
+
|
202
212
|
let current = Reflect.get(target, key, receiver);
|
203
|
-
|
213
|
+
if(proxy.proxyMap.has(current)) {
|
214
|
+
current= proxy.proxyMap.get(current);
|
215
|
+
}
|
216
|
+
|
204
217
|
if (current === value) {
|
205
218
|
return true;
|
206
219
|
}
|
207
220
|
|
208
221
|
let result;
|
209
|
-
//if (value === undefined) {
|
210
222
|
let descriptor = Reflect.getOwnPropertyDescriptor(target, key);
|
211
223
|
|
212
224
|
if (descriptor === undefined) {
|
@@ -217,15 +229,8 @@ function getHandler() {
|
|
217
229
|
}
|
218
230
|
}
|
219
231
|
|
220
|
-
//delete target[key];
|
221
232
|
descriptor['value'] = value;
|
222
233
|
result = Reflect.defineProperty(target, key, descriptor);
|
223
|
-
// } else {
|
224
|
-
// result = Reflect.set(target, key, value, receiver);
|
225
|
-
// }
|
226
|
-
|
227
|
-
// let descriptor3 = Reflect.getOwnPropertyDescriptor(target, key);
|
228
|
-
// console.log(descriptor3, 'descriptor3');
|
229
234
|
|
230
235
|
if (typeof key !== "symbol") {
|
231
236
|
proxy.observers.notify(proxy);
|
@@ -234,6 +239,7 @@ function getHandler() {
|
|
234
239
|
return result;
|
235
240
|
},
|
236
241
|
|
242
|
+
|
237
243
|
// https://262.ecma-international.org/9.0/#sec-proxy-object-internal-methods-and-internal-slots-delete-p
|
238
244
|
deleteProperty: function (target, key) {
|
239
245
|
if (key in target) {
|