@schukai/monster 1.27.0 → 1.29.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG +32 -1
- 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 -2
- 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 +2 -2
- package/dist/modules/dom/customcontrol.js +1 -1
- package/dist/modules/dom/customelement.js +2 -2
- package/dist/modules/dom/events.js +2 -2
- 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 +1 -1
- 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 +1 -1
- 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 +1 -1
- package/dist/modules/types/mediatype.js +1 -1
- package/dist/modules/types/namespace.js +1 -1
- package/dist/modules/types/node.js +2 -2
- package/dist/modules/types/nodelist.js +2 -2
- package/dist/modules/types/noderecursiveiterator.js +2 -2
- 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 +1 -1
- 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/deadmansswitch.js +2 -0
- 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 +498 -322
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +2 -2
- package/package.json +1 -1
- package/source/constraints/andoperator.js +5 -5
- package/source/constraints/invalid.js +3 -3
- package/source/constraints/isarray.js +3 -3
- package/source/constraints/isobject.js +3 -3
- package/source/constraints/oroperator.js +5 -5
- package/source/constraints/valid.js +3 -3
- package/source/data/buildmap.js +10 -11
- package/source/data/buildtree.js +51 -17
- 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 +26 -26
- package/source/dom/constants.js +9 -1
- package/source/dom/customcontrol.js +1 -1
- package/source/dom/customelement.js +27 -13
- package/source/dom/events.js +66 -9
- package/source/dom/focusmanager.js +2 -2
- package/source/dom/locale.js +2 -2
- 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 +67 -24
- package/source/dom/util.js +6 -6
- package/source/dom/worker/factory.js +2 -2
- package/source/i18n/formatter.js +4 -4
- package/source/i18n/locale.js +4 -4
- package/source/i18n/provider.js +2 -2
- package/source/i18n/providers/fetch.js +3 -3
- package/source/i18n/translations.js +4 -4
- 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 +3 -3
- package/source/types/base.js +2 -2
- package/source/types/basewithoptions.js +32 -6
- 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 +2 -2
- package/source/types/is.js +20 -20
- package/source/types/mediatype.js +4 -4
- package/source/types/node.js +33 -2
- package/source/types/nodelist.js +9 -5
- package/source/types/noderecursiveiterator.js +29 -7
- package/source/types/observer.js +5 -13
- package/source/types/observerlist.js +2 -2
- package/source/types/proxyobserver.js +5 -5
- package/source/types/queue.js +3 -3
- package/source/types/randomid.js +2 -2
- package/source/types/regex.js +2 -2
- 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/deadmansswitch.js +124 -0
- 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 +84 -21
- package/test/cases/dom/events.js +66 -1
- package/test/cases/dom/updater.js +76 -3
- package/test/cases/math/random.js +3 -0
- package/test/cases/monster.js +1 -1
- package/test/cases/types/node.js +57 -1
- package/test/cases/types/nodelist.js +7 -0
- package/test/cases/types/noderecursiveiterator.js +21 -0
- package/test/cases/util/deadmansswitch.js +71 -0
- package/test/web/import.js +1 -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 +2 -2
@@ -0,0 +1,124 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @author schukai GmbH
|
5
|
+
*/
|
6
|
+
|
7
|
+
|
8
|
+
import {internalSymbol} from "../constants.js";
|
9
|
+
import {assignToNamespace, Monster} from '../namespace.js';
|
10
|
+
import {Base} from "../types/base.js";
|
11
|
+
import {isInteger} from "../types/is.js";
|
12
|
+
import {validateFunction, validateInteger} from "../types/validate.js";
|
13
|
+
|
14
|
+
/**
|
15
|
+
* The dead man's switch allows to set a timer which can be reset again and again within a defined period of time.
|
16
|
+
*
|
17
|
+
* You can create an instance via the monster namespace `Monster.Util.DeadMansSwitch()`.
|
18
|
+
*
|
19
|
+
* ```
|
20
|
+
* <script type="module">
|
21
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.29.1/dist/monster.js';
|
22
|
+
* new Monster.Util.DeadMansSwitch()
|
23
|
+
* </script>
|
24
|
+
* ```
|
25
|
+
*
|
26
|
+
* Alternatively, you can also integrate this class individually.
|
27
|
+
*
|
28
|
+
* ```
|
29
|
+
* <script type="module">
|
30
|
+
* import {DeadMansSwitch} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.29.1/dist/modules/util/deadmansswitch.js';
|
31
|
+
* new DeadMansSwitch();
|
32
|
+
* </script>
|
33
|
+
* ```
|
34
|
+
*
|
35
|
+
* @example
|
36
|
+
* import {DeadMansSwitch} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.29.1/dist/modules/util/deadmansswitch.js';
|
37
|
+
*
|
38
|
+
* const deadmansswitch = new DeadMansSwitch(100, ()=>{
|
39
|
+
* console.log('yeah!')
|
40
|
+
* // ↦ "yeah!"
|
41
|
+
* })
|
42
|
+
*
|
43
|
+
* deadmansswitch.touch(); // from here wait again 100 ms
|
44
|
+
* deadmansswitch.touch(200); // from here wait 200 ms
|
45
|
+
*
|
46
|
+
* @copyright schukai GmbH
|
47
|
+
* @since 1.29.0
|
48
|
+
* @memberOf Monster.Util
|
49
|
+
* @summary Class to be able to execute function chains
|
50
|
+
*/
|
51
|
+
class DeadMansSwitch extends Base {
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Create new dead man's switch
|
55
|
+
*
|
56
|
+
* @param {Integer} delay
|
57
|
+
* @param {function} callback
|
58
|
+
* @throw {TypeError} the arguments must be either integer or functions
|
59
|
+
* @throws {TypeError} value is not an integer
|
60
|
+
*/
|
61
|
+
constructor(delay, callback) {
|
62
|
+
super();
|
63
|
+
|
64
|
+
init.call(this, validateInteger(delay), validateFunction(callback));
|
65
|
+
}
|
66
|
+
|
67
|
+
/**
|
68
|
+
*
|
69
|
+
* @param {Integer|undefined} [delay]
|
70
|
+
*/
|
71
|
+
touch(delay) {
|
72
|
+
|
73
|
+
if (this[internalSymbol]['isAlreadyRun'] === true) {
|
74
|
+
throw new Error('has already run')
|
75
|
+
}
|
76
|
+
|
77
|
+
if (isInteger(delay)) {
|
78
|
+
this[internalSymbol]['delay'] = delay
|
79
|
+
} else if (delay !== undefined) {
|
80
|
+
throw new Error('unsupported argument')
|
81
|
+
}
|
82
|
+
|
83
|
+
clearTimeout(this[internalSymbol]['timer']);
|
84
|
+
|
85
|
+
initCallback.call(this);
|
86
|
+
|
87
|
+
return this;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
/**
|
92
|
+
* @private
|
93
|
+
*/
|
94
|
+
function initCallback() {
|
95
|
+
|
96
|
+
const self = this;
|
97
|
+
|
98
|
+
self[internalSymbol]['timer'] = setTimeout(() => {
|
99
|
+
self[internalSymbol]['isAlreadyRun'] = true;
|
100
|
+
self[internalSymbol]['callback']();
|
101
|
+
}, self[internalSymbol]['delay'])
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
* @private
|
106
|
+
* @param {integer} delay
|
107
|
+
* @param {function} callback
|
108
|
+
*/
|
109
|
+
function init(delay, callback) {
|
110
|
+
const self = this;
|
111
|
+
|
112
|
+
self[internalSymbol] = {
|
113
|
+
callback,
|
114
|
+
delay,
|
115
|
+
isAlreadyRun: false,
|
116
|
+
timer: undefined
|
117
|
+
};
|
118
|
+
|
119
|
+
initCallback.call(self);
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
assignToNamespace('Monster.Util', DeadMansSwitch);
|
124
|
+
export {Monster, DeadMansSwitch}
|
package/source/util/freeze.js
CHANGED
@@ -14,7 +14,7 @@ import {validateObject} from '../types/validate.js';
|
|
14
14
|
*
|
15
15
|
* ```
|
16
16
|
* <script type="module">
|
17
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
17
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.29.1/dist/monster.js';
|
18
18
|
* Monster.Util.deepFreeze({})
|
19
19
|
* </script>
|
20
20
|
* ```
|
@@ -23,7 +23,7 @@ import {validateObject} from '../types/validate.js';
|
|
23
23
|
*
|
24
24
|
* ```
|
25
25
|
* <script type="module">
|
26
|
-
* import {deepFreeze} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
26
|
+
* import {deepFreeze} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.29.1/dist/modules/util/freeze.js';
|
27
27
|
* deepFreeze({})
|
28
28
|
* </script>
|
29
29
|
* ```
|
@@ -77,7 +77,7 @@ class Callback {
|
|
77
77
|
*
|
78
78
|
* ```
|
79
79
|
* <script type="module">
|
80
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
80
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.29.1/dist/monster.js';
|
81
81
|
* new Monster.Util.Processing()
|
82
82
|
* </script>
|
83
83
|
* ```
|
@@ -86,13 +86,13 @@ class Callback {
|
|
86
86
|
*
|
87
87
|
* ```
|
88
88
|
* <script type="module">
|
89
|
-
* import {Processing} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
89
|
+
* import {Processing} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.29.1/dist/modules/util/processing.js';
|
90
90
|
* new Processing();
|
91
91
|
* </script>
|
92
92
|
* ```
|
93
93
|
*
|
94
94
|
* @example
|
95
|
-
* import {Processing} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
95
|
+
* import {Processing} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.29.1/dist/modules/util/processing.js';
|
96
96
|
*
|
97
97
|
* let startTime = +new Date();
|
98
98
|
*
|
@@ -16,7 +16,7 @@ import {validateString} from "../types/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.29.1/dist/monster.js';
|
20
20
|
* Monster.Util.trimSpaces(" hello ")
|
21
21
|
* </script>
|
22
22
|
* ```
|
@@ -25,7 +25,7 @@ import {validateString} from "../types/validate.js";
|
|
25
25
|
*
|
26
26
|
* ```
|
27
27
|
* <script type="module">
|
28
|
-
* import {trimSpaces} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
28
|
+
* import {trimSpaces} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.29.1/dist/modules/util/trimspaces.js';
|
29
29
|
* trimSpaces(' hello \\ ')
|
30
30
|
* </script>
|
31
31
|
* ```
|
@@ -3,7 +3,6 @@
|
|
3
3
|
import {expect} from "chai"
|
4
4
|
import {buildTree} from "../../../source/data/buildtree.js";
|
5
5
|
import {NodeList} from "../../../source/types/nodelist.js";
|
6
|
-
import {NodeRecursiveIterator} from "../../../source/types/noderecursiveiterator.js";
|
7
6
|
|
8
7
|
|
9
8
|
describe('buildTree', function () {
|
@@ -50,18 +49,9 @@ describe('buildTree', function () {
|
|
50
49
|
|
51
50
|
const nodes = buildTree(objects, 'dataset.*', 'id', 'parent');
|
52
51
|
|
53
|
-
let result = ""
|
54
|
-
nodes.forEach(node => {
|
55
|
-
new NodeRecursiveIterator(node).forEach(n => {
|
56
|
-
result +="".padStart(n.level * 2, '.') + (n.value.name);
|
57
|
-
});
|
58
|
-
|
59
|
-
});
|
60
|
-
|
61
|
-
expect(result).to.be.equal('vehicle..car....SUV....sports car..truck..motorcycle');
|
62
52
|
expect(nodes).to.be.instanceOf(NodeList);
|
63
53
|
expect(nodes.length).to.equal(1);
|
64
|
-
expect(nodes.
|
54
|
+
expect(nodes.toString()).to.be.equal('{"id":"1","name":"vehicle","parent":null}\n ├{"id":"2","name":"car","parent":"1"}\n | ├{"id":"5","name":"SUV","parent":"2"}\n | └{"id":"6","name":"sports car","parent":"2"}\n ├{"id":"3","name":"truck","parent":"1"}\n └{"id":"4","name":"motorcycle","parent":"1"}' );
|
65
55
|
|
66
56
|
|
67
57
|
})
|
@@ -116,9 +106,9 @@ describe('buildTree', function () {
|
|
116
106
|
});
|
117
107
|
|
118
108
|
[
|
119
|
-
[obj1, 'dataset.*', '1,2,3,4,6,5'],
|
109
|
+
[obj1, 'dataset.*', '{"id":"1","name":"Test 1","address":"Here 1","parent":null}\n ├{"id":"2","name":"Test 2","address":"Here 2","parent":"1"}\n | ├{"id":"3","name":"Test 3","address":"Here 3","parent":"2"}\n | └{"id":"4","name":"Test 4","address":"Here 4","parent":"2"}\n | | └{"id":"6","name":"Test 6","address":"Here 6","parent":"4"}\n └{"id":"5","name":"Test 5","address":"Here 5","parent":"1"}'],
|
120
110
|
[obj1, 'x', ''],
|
121
|
-
[obj1, 'dataset.*', '1,2,3,4,6,5'],
|
111
|
+
[obj1, 'dataset.*', '{"id":"1","name":"Test 1","address":"Here 1","parent":null}\n ├{"id":"2","name":"Test 2","address":"Here 2","parent":"1"}\n | ├{"id":"3","name":"Test 3","address":"Here 3","parent":"2"}\n | └{"id":"4","name":"Test 4","address":"Here 4","parent":"2"}\n | | └{"id":"6","name":"Test 6","address":"Here 6","parent":"4"}\n └{"id":"5","name":"Test 5","address":"Here 5","parent":"1"}'],
|
122
112
|
].forEach(function (data) {
|
123
113
|
|
124
114
|
let a = data.shift()
|
@@ -127,18 +117,91 @@ describe('buildTree', function () {
|
|
127
117
|
|
128
118
|
it('buildTree(' + JSON.stringify(a) + ',' + JSON.stringify(b) + ') should return ' + JSON.stringify(c) + ' ', function () {
|
129
119
|
let nodelist = buildTree(a, b, 'id', 'parent');
|
120
|
+
expect(nodelist.toString()).to.be.eql(c);
|
121
|
+
});
|
122
|
+
});
|
130
123
|
|
131
|
-
let result = [];
|
132
124
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
125
|
+
});
|
126
|
+
|
127
|
+
describe('buildTree() test 2', function () {
|
128
|
+
|
129
|
+
/**
|
130
|
+
* 2
|
131
|
+
* 1
|
132
|
+
* 3
|
133
|
+
* 4
|
134
|
+
* 6
|
135
|
+
* 5
|
136
|
+
*
|
137
|
+
*/
|
138
|
+
let obj1 = {
|
139
|
+
dataset: {
|
140
|
+
"1": {
|
141
|
+
id: "1",
|
142
|
+
name: "Test 1",
|
143
|
+
address: "Here 1",
|
144
|
+
parent: "2"
|
145
|
+
},
|
146
|
+
"2": {
|
147
|
+
id: "2",
|
148
|
+
name: "Test 2",
|
149
|
+
address: "Here 2",
|
150
|
+
parent: "0"
|
151
|
+
},
|
152
|
+
"3": {
|
153
|
+
id: "3",
|
154
|
+
name: "Test 3",
|
155
|
+
address: "Here 3",
|
156
|
+
parent: "2"
|
157
|
+
},
|
158
|
+
"4": {
|
159
|
+
id: "4",
|
160
|
+
name: "Test 4",
|
161
|
+
address: "Here 4",
|
162
|
+
parent: "0"
|
163
|
+
},
|
164
|
+
"5": {
|
165
|
+
id: "5",
|
166
|
+
name: "Test 5",
|
167
|
+
address: "Here 5",
|
168
|
+
parent: "0"
|
169
|
+
},
|
170
|
+
"6": {
|
171
|
+
id: "6",
|
172
|
+
name: "Test 6",
|
173
|
+
address: "Here 6",
|
174
|
+
parent: "4"
|
175
|
+
},
|
176
|
+
"7": {
|
177
|
+
id: "7",
|
178
|
+
name: "Test 7",
|
179
|
+
address: "Here 7",
|
180
|
+
parent: "1"
|
139
181
|
}
|
182
|
+
}
|
183
|
+
};
|
184
|
+
|
185
|
+
it('should return Node Instance.', function () {
|
186
|
+
expect(buildTree({}, '')).to.be.instanceOf(NodeList);
|
187
|
+
});
|
188
|
+
|
189
|
+
[
|
190
|
+
[obj1, 'dataset.*', '{"id":"2","name":"Test 2","address":"Here 2","parent":"0"}\n ├{"id":"1","name":"Test 1","address":"Here 1","parent":"2"}\n | └{"id":"7","name":"Test 7","address":"Here 7","parent":"1"}\n └{"id":"3","name":"Test 3","address":"Here 3","parent":"2"}\n{"id":"4","name":"Test 4","address":"Here 4","parent":"0"}\n └{"id":"6","name":"Test 6","address":"Here 6","parent":"4"}\n{"id":"5","name":"Test 5","address":"Here 5","parent":"0"}'],
|
191
|
+
[obj1, 'x', ''],
|
192
|
+
].forEach(function (data) {
|
193
|
+
|
194
|
+
let a = data.shift()
|
195
|
+
let b = data.shift()
|
196
|
+
let c = data.shift()
|
197
|
+
|
198
|
+
it('buildTree(' + JSON.stringify(a) + ',' + JSON.stringify(b) + ') should return ' + JSON.stringify(c) + ' ', function () {
|
199
|
+
let nodelist = buildTree(a, b, 'id', 'parent', {
|
200
|
+
rootReferences: ['0']
|
201
|
+
});
|
202
|
+
|
203
|
+
expect(nodelist.toString()).to.be.equal(c);
|
140
204
|
|
141
|
-
expect(result.join(',')).to.be.equal(c);
|
142
205
|
});
|
143
206
|
});
|
144
207
|
|
package/test/cases/dom/events.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
import {expect} from "chai"
|
4
4
|
|
5
|
-
import {fireEvent, findTargetElementFromEvent} from "../../../source/dom/events.js";
|
5
|
+
import {fireEvent, findTargetElementFromEvent, fireCustomEvent} from "../../../source/dom/events.js";
|
6
6
|
import {initJSDOM} from "../../util/jsdom.js";
|
7
7
|
|
8
8
|
describe('Events', function () {
|
@@ -78,6 +78,71 @@ describe('Events', function () {
|
|
78
78
|
expect(() => fireEvent({}, 'touch')).to.throw(Error);
|
79
79
|
|
80
80
|
});
|
81
|
+
});
|
82
|
+
|
83
|
+
describe('fireCustomEvent()', function () {
|
84
|
+
it('should fire a click event', function (done) {
|
85
|
+
let div = document.createElement('div');
|
86
|
+
div.addEventListener('click', () => {
|
87
|
+
done();
|
88
|
+
})
|
89
|
+
fireCustomEvent(div, 'click');
|
90
|
+
});
|
91
|
+
|
92
|
+
it('should fire a touch event', function (done) {
|
93
|
+
let div = document.createElement('div');
|
94
|
+
div.addEventListener('touch', () => {
|
95
|
+
done();
|
96
|
+
})
|
97
|
+
fireCustomEvent(div, 'touch');
|
98
|
+
});
|
99
|
+
|
100
|
+
it('should fire a touch event on collection1', function (done) {
|
101
|
+
let div = document.createElement('div');
|
102
|
+
div.addEventListener('touch', (e) => {
|
103
|
+
if(e.detail.detail!=='hello world') {
|
104
|
+
done('error');
|
105
|
+
}
|
106
|
+
done();
|
107
|
+
})
|
108
|
+
|
109
|
+
div.appendChild(document.createElement('div'));
|
110
|
+
let collection = div.querySelectorAll('div');
|
111
|
+
|
112
|
+
fireCustomEvent(collection, 'touch', "hello world");
|
113
|
+
});
|
114
|
+
|
115
|
+
it('should fire a touch event on collection2', function (done) {
|
116
|
+
let div = document.createElement('div');
|
117
|
+
div.addEventListener('touch', (e) => {
|
118
|
+
if(e.detail.a!=='hello world') {
|
119
|
+
done('error');
|
120
|
+
}
|
121
|
+
done();
|
122
|
+
})
|
123
|
+
|
124
|
+
div.appendChild(document.createElement('div'));
|
125
|
+
let collection = div.querySelectorAll('div');
|
126
|
+
|
127
|
+
fireCustomEvent(collection, 'touch', {a:"hello world"});
|
128
|
+
});
|
129
|
+
|
130
|
+
it('should fire a touch event', function (done) {
|
131
|
+
let div = document.createElement('div');
|
132
|
+
div.addEventListener('touch', () => {
|
133
|
+
done();
|
134
|
+
})
|
135
|
+
|
136
|
+
div.appendChild(document.createElement('div'));
|
137
|
+
let collection = div.querySelectorAll('div');
|
138
|
+
|
139
|
+
|
140
|
+
fireCustomEvent(collection, 'touch');
|
141
|
+
});
|
142
|
+
|
143
|
+
it('should throw error', function () {
|
144
|
+
expect(() => fireCustomEvent({}, 'touch')).to.throw(Error);
|
145
|
+
});
|
81
146
|
});
|
82
147
|
|
83
148
|
|
@@ -664,7 +664,7 @@ describe('DOM', function () {
|
|
664
664
|
|
665
665
|
describe('manuel update', function () {
|
666
666
|
let id, mocks;
|
667
|
-
|
667
|
+
|
668
668
|
beforeEach(() => {
|
669
669
|
mocks = document.getElementById('mocks');
|
670
670
|
id = new ID('monster').toString();
|
@@ -677,10 +677,10 @@ describe('DOM', function () {
|
|
677
677
|
|
678
678
|
it('should get value', function () {
|
679
679
|
|
680
|
-
document.getElementById(id).value="hello";
|
680
|
+
document.getElementById(id).value = "hello";
|
681
681
|
const updater = new Updater(mocks);
|
682
682
|
const subject = updater.getSubject();
|
683
|
-
|
683
|
+
|
684
684
|
expect(subject).to.not.have.property('myvalue');
|
685
685
|
updater.retrieve();
|
686
686
|
expect(subject).to.have.property('myvalue');
|
@@ -688,4 +688,77 @@ describe('DOM', function () {
|
|
688
688
|
|
689
689
|
|
690
690
|
});
|
691
|
+
|
692
|
+
|
693
|
+
/**
|
694
|
+
* https://gitlab.schukai.com/oss/libraries/javascript/monster/-/issues/112
|
695
|
+
*/
|
696
|
+
describe('Updater() 20220107', function () {
|
697
|
+
|
698
|
+
beforeEach(() => {
|
699
|
+
let mocks = document.getElementById('mocks');
|
700
|
+
// language=HTML
|
701
|
+
mocks.innerHTML = `
|
702
|
+
|
703
|
+
<div id="container">
|
704
|
+
<div data-monster-replace="path:content"></div>
|
705
|
+
</div>
|
706
|
+
|
707
|
+
|
708
|
+
`;
|
709
|
+
})
|
710
|
+
|
711
|
+
describe('Bugfix #112', function () {
|
712
|
+
|
713
|
+
it('should add ', function (done) {
|
714
|
+
let containerElement = document.getElementById('container');
|
715
|
+
let newElement = document.createElement('div');
|
716
|
+
newElement.innerHTML = 'yeah! <b>Test</b>!';
|
717
|
+
|
718
|
+
const containerHTML = containerElement.innerHTML;
|
719
|
+
const newHTML = newElement.innerHTML;
|
720
|
+
|
721
|
+
let d = new Updater(
|
722
|
+
containerElement,
|
723
|
+
{
|
724
|
+
content: newElement
|
725
|
+
}
|
726
|
+
);
|
727
|
+
setTimeout(() => {
|
728
|
+
d.run().then(() => {
|
729
|
+
try {
|
730
|
+
expect(containerElement).contain.html('<div>yeah! <b>Test</b>!</div>');
|
731
|
+
} catch (e) {
|
732
|
+
return done(e);
|
733
|
+
}
|
734
|
+
|
735
|
+
|
736
|
+
done()
|
737
|
+
})
|
738
|
+
}, 100)
|
739
|
+
|
740
|
+
// d.setCallback('myformatter', function (a) {
|
741
|
+
// return a + 'yes!'
|
742
|
+
// })
|
743
|
+
//
|
744
|
+
// setTimeout(() => {
|
745
|
+
// d.run().then(() => {
|
746
|
+
//
|
747
|
+
// expect(typeof d).is.equal('object');
|
748
|
+
// expect(element).contain.html('<div data-monster-replace="path:text | tolower">hallo</div>');
|
749
|
+
// expect(element).contain.html('<div data-monster-replace="path:text | call:myformatter">HALLOyes!</div>');
|
750
|
+
// expect(element).contain.html('<div data-monster-replace="static:hello\\ ">hello </div>');
|
751
|
+
//
|
752
|
+
// return done();
|
753
|
+
// }).catch(
|
754
|
+
// e => {
|
755
|
+
// done(new Error(e))
|
756
|
+
// })
|
757
|
+
// }, 100)
|
758
|
+
|
759
|
+
});
|
760
|
+
});
|
761
|
+
});
|
762
|
+
|
763
|
+
|
691
764
|
});
|
@@ -1,8 +1,11 @@
|
|
1
1
|
/** nodejs doesnt support window.crypt */
|
2
2
|
import {expect} from "chai"
|
3
|
+
import {getGlobal} from "../../../source/types/global.js";
|
3
4
|
import * as Crypto from "@peculiar/webcrypto";
|
4
5
|
import {Monster, random} from "../../../source/math/random.js";
|
5
6
|
|
7
|
+
const global = getGlobal();
|
8
|
+
|
6
9
|
if (!global['crypto']) {
|
7
10
|
global['crypto'] = new Crypto.Crypto();
|
8
11
|
}
|
package/test/cases/monster.js
CHANGED
package/test/cases/types/node.js
CHANGED
@@ -102,7 +102,7 @@ describe('NodeList', function () {
|
|
102
102
|
result.push(n.value + ":" + n.level);
|
103
103
|
}
|
104
104
|
|
105
|
-
|
105
|
+
|
106
106
|
expect(result).to.deep.equal([
|
107
107
|
'root:0',
|
108
108
|
'n1:1',
|
@@ -192,5 +192,61 @@ describe('NodeList', function () {
|
|
192
192
|
|
193
193
|
})
|
194
194
|
|
195
|
+
describe('Levels', function () {
|
196
|
+
|
197
|
+
it('n2 should level 2', function () {
|
198
|
+
|
199
|
+
const n0 = new Node('abc');
|
200
|
+
|
201
|
+
const n1 = new Node('def');
|
202
|
+
n0.appendChild(n1)
|
203
|
+
|
204
|
+
const n2 = new Node('ghi');
|
205
|
+
n1.appendChild(n2);
|
206
|
+
|
207
|
+
const n3 = new Node('jkl');
|
208
|
+
n2.appendChild(n3);
|
209
|
+
|
210
|
+
expect(n0.level).to.be.equal(0);
|
211
|
+
expect(n1.level).to.be.equal(1);
|
212
|
+
expect(n2.level).to.be.equal(2);
|
213
|
+
expect(n3.level).to.be.equal(3);
|
214
|
+
|
215
|
+
});
|
216
|
+
});
|
217
|
+
|
218
|
+
|
219
|
+
describe('toString()', function () {
|
220
|
+
|
221
|
+
it('should output empty string', function () {
|
222
|
+
const node = new Node();
|
223
|
+
expect(node.toString()).is.equal('');
|
224
|
+
});
|
225
|
+
|
226
|
+
it('should output string', function () {
|
227
|
+
const n0 = new Node('abc');
|
228
|
+
|
229
|
+
const n1 = new Node('def');
|
230
|
+
n0.appendChild(n1)
|
231
|
+
|
232
|
+
const n11 = new Node('ghi');
|
233
|
+
n0.appendChild(n11)
|
234
|
+
|
235
|
+
const n2 = new Node('jkl');
|
236
|
+
n1.appendChild(n2);
|
237
|
+
|
238
|
+
const n3 = new Node('mno');
|
239
|
+
n1.appendChild(n3);
|
240
|
+
|
241
|
+
const n4 = new Node('pqr');
|
242
|
+
n2.appendChild(n4);
|
243
|
+
|
244
|
+
expect(n2.level).to.be.equal(2)
|
245
|
+
|
246
|
+
console.log(n0.toString());
|
247
|
+
// expect(n0.toString()).is.equal('');
|
248
|
+
});
|
249
|
+
});
|
250
|
+
|
195
251
|
|
196
252
|
});
|
@@ -33,8 +33,10 @@ describe('NodeList', function () {
|
|
33
33
|
|
34
34
|
expect(nodeList2.size).to.equal(3);
|
35
35
|
});
|
36
|
+
|
36
37
|
});
|
37
38
|
|
39
|
+
|
38
40
|
it('create NodeList', function () {
|
39
41
|
expect(new NodeList()).is.instanceof(NodeList);
|
40
42
|
})
|
@@ -55,6 +57,11 @@ describe('NodeList', function () {
|
|
55
57
|
const n = new Node;
|
56
58
|
expect(new NodeList().add(n).has(n)).to.be.true;
|
57
59
|
})
|
60
|
+
|
61
|
+
it('toString', function () {
|
62
|
+
const n = new Node;
|
63
|
+
expect(new NodeList().add(new Node('a').appendChild(new Node('b'))).toString()).to.be.equal('a\n └b');
|
64
|
+
})
|
58
65
|
|
59
66
|
it('throw exception', function () {
|
60
67
|
expect(() => new NodeList().add(1)).to.throw(Error);
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
import {expect} from "chai"
|
4
4
|
import {Node} from "../../../source/types/node.js";
|
5
|
+
import {NodeList} from "../../../source/types/nodelist.js";
|
5
6
|
import {NodeRecursiveIterator} from "../../../source/types/noderecursiveiterator.js";
|
6
7
|
|
7
8
|
describe('NodeRecursiveIterator', function () {
|
@@ -51,4 +52,24 @@ describe('NodeRecursiveIterator', function () {
|
|
51
52
|
|
52
53
|
});
|
53
54
|
|
55
|
+
it('should iterate nodelist', function () {
|
56
|
+
const nodeList = new NodeList();
|
57
|
+
|
58
|
+
nodeList.add(
|
59
|
+
(new Node('2')).appendChild(new Node('2.1')).appendChild(new Node('2.2')).appendChild(new Node('2.3')).appendChild(new Node('3')).appendChild(new Node('4').appendChild(new Node('4.1')).appendChild(new Node('4.2'))));
|
60
|
+
|
61
|
+
nodeList.add(new Node('x'));
|
62
|
+
|
63
|
+
const iterator = new NodeRecursiveIterator(nodeList);
|
64
|
+
|
65
|
+
const result = [];
|
66
|
+
for (const n of iterator) {
|
67
|
+
expect(n).to.be.an.instanceof(Node);
|
68
|
+
result.push(n.value);
|
69
|
+
}
|
70
|
+
|
71
|
+
expect(result).to.deep.equal(['2', '2.1', '2.2', '2.3', '3', '4', '4.1', '4.2', 'x']);
|
72
|
+
|
73
|
+
});
|
74
|
+
|
54
75
|
});
|