@schukai/monster 3.4.2 → 3.7.0
Sign up to get free protection for your applications and to get access to all the features.
- package/example/i18n/providers/embed.mjs +5 -0
- package/package.json +1 -1
- package/source/constants.mjs +4 -9
- package/source/constraints/abstract.mjs +4 -6
- package/source/constraints/abstractoperator.mjs +6 -12
- package/source/constraints/andoperator.mjs +3 -6
- package/source/constraints/invalid.mjs +3 -6
- package/source/constraints/isarray.mjs +6 -9
- package/source/constraints/isobject.mjs +4 -7
- package/source/constraints/namespace.mjs +1 -3
- package/source/constraints/oroperator.mjs +26 -25
- package/source/constraints/valid.mjs +3 -6
- package/source/data/buildmap.mjs +20 -36
- package/source/data/buildtree.mjs +29 -29
- package/source/data/datasource/namespace.mjs +1 -1
- package/source/data/datasource/server/restapi/writeerror.mjs +6 -6
- package/source/data/datasource/server/restapi.mjs +51 -65
- package/source/data/datasource/server/webconnect.mjs +26 -35
- package/source/data/datasource/server.mjs +17 -21
- package/source/data/datasource/storage/localstorage.mjs +8 -11
- package/source/data/datasource/storage/sessionstorage.mjs +8 -10
- package/source/data/datasource/storage.mjs +18 -22
- package/source/data/datasource.mjs +27 -43
- package/source/data/diff.mjs +20 -32
- package/source/data/extend.mjs +20 -14
- package/source/data/namespace.mjs +1 -3
- package/source/data/pathfinder.mjs +40 -67
- package/source/data/pipe.mjs +6 -10
- package/source/data/transformer.mjs +141 -157
- package/source/dom/assembler.mjs +6 -9
- package/source/dom/attributes.mjs +36 -48
- package/source/dom/constants.mjs +55 -71
- package/source/dom/customcontrol.mjs +16 -21
- package/source/dom/customelement.mjs +140 -164
- package/source/dom/events.mjs +17 -24
- package/source/dom/focusmanager.mjs +30 -48
- package/source/dom/locale.mjs +41 -10
- package/source/dom/namespace.mjs +1 -1
- package/source/dom/ready.mjs +7 -10
- package/source/dom/resource/data.mjs +38 -46
- package/source/dom/resource/link/namespace.mjs +1 -3
- package/source/dom/resource/link/stylesheet.mjs +7 -11
- package/source/dom/resource/link.mjs +36 -17
- package/source/dom/resource/namespace.mjs +1 -1
- package/source/dom/resource/script.mjs +23 -13
- package/source/dom/resource.mjs +47 -60
- package/source/dom/resourcemanager.mjs +36 -43
- package/source/dom/template.mjs +17 -24
- package/source/dom/theme.mjs +8 -12
- package/source/dom/updater.mjs +150 -196
- package/source/dom/util.mjs +11 -12
- package/source/dom/worker/factory.mjs +21 -25
- package/source/dom/worker/namespace.mjs +1 -1
- package/source/i18n/formatter.mjs +20 -24
- package/source/i18n/locale.mjs +40 -42
- package/source/i18n/namespace.mjs +1 -1
- package/source/i18n/provider.mjs +4 -7
- package/source/i18n/providers/embed.mjs +115 -0
- package/source/i18n/providers/fetch.mjs +33 -38
- package/source/i18n/translations.mjs +16 -20
- package/source/logging/handler/console.mjs +6 -10
- package/source/logging/handler.mjs +15 -18
- package/source/logging/logentry.mjs +8 -9
- package/source/logging/logger.mjs +73 -55
- package/source/logging/namespace.mjs +1 -1
- package/source/math/namespace.mjs +1 -1
- package/source/math/random.mjs +13 -14
- package/source/monster.mjs +132 -100
- package/source/net/namespace.mjs +1 -3
- package/source/net/webconnect/message.mjs +6 -8
- package/source/net/webconnect/namespace.mjs +1 -3
- package/source/net/webconnect.mjs +28 -39
- package/source/text/formatter.mjs +44 -55
- package/source/types/base.mjs +16 -26
- package/source/types/basewithoptions.mjs +8 -14
- package/source/types/binary.mjs +4 -5
- package/source/types/dataurl.mjs +19 -27
- package/source/types/global.mjs +14 -26
- package/source/types/id.mjs +4 -6
- package/source/types/is.mjs +11 -16
- package/source/types/mediatype.mjs +29 -44
- package/source/types/namespace.mjs +0 -1
- package/source/types/node.mjs +16 -22
- package/source/types/nodelist.mjs +10 -14
- package/source/types/noderecursiveiterator.mjs +11 -14
- package/source/types/observablequeue.mjs +13 -16
- package/source/types/observer.mjs +16 -23
- package/source/types/observerlist.mjs +18 -21
- package/source/types/proxyobserver.mjs +24 -37
- package/source/types/queue.mjs +8 -13
- package/source/types/randomid.mjs +10 -10
- package/source/types/regex.mjs +3 -5
- package/source/types/stack.mjs +4 -8
- package/source/types/tokenlist.mjs +24 -31
- package/source/types/typeof.mjs +5 -7
- package/source/types/uniquequeue.mjs +8 -13
- package/source/types/uuid.mjs +18 -25
- package/source/types/validate.mjs +26 -27
- package/source/types/version.mjs +17 -25
- package/source/util/clone.mjs +23 -32
- package/source/util/comparator.mjs +7 -15
- package/source/util/deadmansswitch.mjs +16 -23
- package/source/util/freeze.mjs +5 -7
- package/source/util/namespace.mjs +1 -1
- package/source/util/processing.mjs +33 -39
- package/source/util/trimspaces.mjs +17 -24
- package/test/cases/dom/locale.mjs +15 -0
- package/test/cases/i18n/providers/embed.mjs +72 -0
- package/test/cases/monster.mjs +1 -1
package/source/util/clone.mjs
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {getGlobal} from
|
9
|
-
import {isArray, isFunction, isObject, isPrimitive} from
|
10
|
-
import {typeOf} from "../types/typeof.mjs";
|
11
|
-
import {validateObject} from "../types/validate.mjs";
|
8
|
+
import { getGlobal } from "../types/global.mjs";
|
9
|
+
import { isArray, isFunction, isObject, isPrimitive } from "../types/is.mjs";
|
10
|
+
import { typeOf } from "../types/typeof.mjs";
|
11
|
+
import { validateObject } from "../types/validate.mjs";
|
12
12
|
|
13
|
-
export {clone}
|
13
|
+
export { clone };
|
14
14
|
|
15
15
|
/**
|
16
16
|
* With this function, objects can be cloned.
|
@@ -30,7 +30,6 @@ export {clone}
|
|
30
30
|
* @throws {Error} unable to clone obj! its type isn't supported.
|
31
31
|
*/
|
32
32
|
function clone(obj) {
|
33
|
-
|
34
33
|
// typeof null results in 'object'. https://2ality.com/2013/10/typeof-null.html
|
35
34
|
if (null === obj) {
|
36
35
|
return obj;
|
@@ -57,8 +56,6 @@ function clone(obj) {
|
|
57
56
|
}
|
58
57
|
|
59
58
|
if (isObject(obj)) {
|
60
|
-
|
61
|
-
|
62
59
|
// Handle Date
|
63
60
|
if (obj instanceof Date) {
|
64
61
|
let copy = new Date();
|
@@ -67,17 +64,17 @@ function clone(obj) {
|
|
67
64
|
}
|
68
65
|
|
69
66
|
/** Do not clone DOM nodes */
|
70
|
-
if (typeof Element !==
|
71
|
-
if (typeof HTMLDocument !==
|
72
|
-
if (typeof DocumentFragment !==
|
67
|
+
if (typeof Element !== "undefined" && obj instanceof Element) return obj;
|
68
|
+
if (typeof HTMLDocument !== "undefined" && obj instanceof HTMLDocument) return obj;
|
69
|
+
if (typeof DocumentFragment !== "undefined" && obj instanceof DocumentFragment) return obj;
|
73
70
|
|
74
71
|
/** Do not clone global objects */
|
75
72
|
if (obj === getGlobal()) return obj;
|
76
|
-
if (typeof globalContext !==
|
77
|
-
if (typeof window !==
|
78
|
-
if (typeof document !==
|
79
|
-
if (typeof navigator !==
|
80
|
-
if (typeof JSON !==
|
73
|
+
if (typeof globalContext !== "undefined" && obj === globalContext) return obj;
|
74
|
+
if (typeof window !== "undefined" && obj === window) return obj;
|
75
|
+
if (typeof document !== "undefined" && obj === document) return obj;
|
76
|
+
if (typeof navigator !== "undefined" && obj === navigator) return obj;
|
77
|
+
if (typeof JSON !== "undefined" && obj === JSON) return obj;
|
81
78
|
|
82
79
|
// Handle Proxy-Object
|
83
80
|
try {
|
@@ -85,11 +82,9 @@ function clone(obj) {
|
|
85
82
|
if (obj instanceof Proxy) {
|
86
83
|
return obj;
|
87
84
|
}
|
88
|
-
} catch (e) {
|
89
|
-
}
|
90
|
-
|
91
|
-
return cloneObject(obj)
|
85
|
+
} catch (e) {}
|
92
86
|
|
87
|
+
return cloneObject(obj);
|
93
88
|
}
|
94
89
|
|
95
90
|
throw new Error("unable to clone obj! its type isn't supported.");
|
@@ -102,29 +97,26 @@ function clone(obj) {
|
|
102
97
|
* @private
|
103
98
|
*/
|
104
99
|
function cloneObject(obj) {
|
105
|
-
|
106
100
|
validateObject(obj);
|
107
|
-
|
108
|
-
const
|
101
|
+
|
102
|
+
const fkt = obj?.["constructor"];
|
109
103
|
|
110
104
|
/** Object has clone method */
|
111
|
-
if(typeOf(
|
112
|
-
const prototype =
|
113
|
-
if(typeof prototype===
|
114
|
-
if(prototype.hasOwnProperty(
|
115
|
-
return obj.getClone();
|
105
|
+
if (typeOf(fkt) === "function") {
|
106
|
+
const prototype = fkt?.prototype;
|
107
|
+
if (typeof prototype === "object") {
|
108
|
+
if (prototype.hasOwnProperty("getClone") && typeOf(obj.getClone) === "function") {
|
109
|
+
return obj.getClone();
|
116
110
|
}
|
117
111
|
}
|
118
112
|
}
|
119
113
|
|
120
114
|
let copy = {};
|
121
|
-
if (typeof obj.constructor ===
|
122
|
-
typeof obj.constructor.call === 'function') {
|
115
|
+
if (typeof obj.constructor === "function" && typeof obj.constructor.call === "function") {
|
123
116
|
copy = new obj.constructor();
|
124
117
|
}
|
125
118
|
|
126
119
|
for (let key in obj) {
|
127
|
-
|
128
120
|
if (!obj.hasOwnProperty(key)) {
|
129
121
|
continue;
|
130
122
|
}
|
@@ -139,4 +131,3 @@ function cloneObject(obj) {
|
|
139
131
|
|
140
132
|
return copy;
|
141
133
|
}
|
142
|
-
|
@@ -5,14 +5,14 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {Base} from
|
9
|
-
import {isFunction} from
|
8
|
+
import { Base } from "../types/base.mjs";
|
9
|
+
import { isFunction } from "../types/is.mjs";
|
10
10
|
|
11
|
-
export {Comparator}
|
11
|
+
export { Comparator };
|
12
12
|
|
13
13
|
/**
|
14
14
|
* The comparator allows a comparison function to be abstracted.
|
15
|
-
*
|
15
|
+
*
|
16
16
|
* The following are some examples of the application of the class.
|
17
17
|
*
|
18
18
|
* ```
|
@@ -37,7 +37,6 @@ export {Comparator}
|
|
37
37
|
* @memberOf Monster.Util
|
38
38
|
*/
|
39
39
|
class Comparator extends Base {
|
40
|
-
|
41
40
|
/**
|
42
41
|
* create new comparator
|
43
42
|
*
|
@@ -49,9 +48,9 @@ class Comparator extends Base {
|
|
49
48
|
super();
|
50
49
|
|
51
50
|
if (isFunction(callback)) {
|
52
|
-
this.compare = callback
|
51
|
+
this.compare = callback;
|
53
52
|
} else if (callback !== undefined) {
|
54
|
-
throw new TypeError("unsupported type")
|
53
|
+
throw new TypeError("unsupported type");
|
55
54
|
} else {
|
56
55
|
// default compare function
|
57
56
|
|
@@ -62,9 +61,8 @@ class Comparator extends Base {
|
|
62
61
|
* @return {integer} -1, 0 or 1
|
63
62
|
*/
|
64
63
|
this.compare = function (a, b) {
|
65
|
-
|
66
64
|
if (typeof a !== typeof b) {
|
67
|
-
throw new TypeError("impractical comparison", "types/comparator.mjs")
|
65
|
+
throw new TypeError("impractical comparison", "types/comparator.mjs");
|
68
66
|
}
|
69
67
|
|
70
68
|
if (a === b) {
|
@@ -73,7 +71,6 @@ class Comparator extends Base {
|
|
73
71
|
return a < b ? -1 : 1;
|
74
72
|
};
|
75
73
|
}
|
76
|
-
|
77
74
|
}
|
78
75
|
|
79
76
|
/**
|
@@ -99,7 +96,6 @@ class Comparator extends Base {
|
|
99
96
|
return this.compare(a, b) === 0;
|
100
97
|
}
|
101
98
|
|
102
|
-
|
103
99
|
/**
|
104
100
|
* Checks if variable `a` is greater than `b`
|
105
101
|
*
|
@@ -147,11 +143,8 @@ class Comparator extends Base {
|
|
147
143
|
lessThan(a, b) {
|
148
144
|
return this.compare(a, b) < 0;
|
149
145
|
}
|
150
|
-
|
151
|
-
|
152
146
|
}
|
153
147
|
|
154
|
-
|
155
148
|
/**
|
156
149
|
* This is the description for the callback function used by the operator
|
157
150
|
*
|
@@ -169,4 +162,3 @@ class Comparator extends Base {
|
|
169
162
|
* @memberOf Monster.Util
|
170
163
|
* @see Monster.Util.Comparator
|
171
164
|
*/
|
172
|
-
|
@@ -5,13 +5,13 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {internalSymbol} from "../constants.mjs";
|
8
|
+
import { internalSymbol } from "../constants.mjs";
|
9
9
|
|
10
|
-
import {Base} from "../types/base.mjs";
|
11
|
-
import {isInteger} from "../types/is.mjs";
|
12
|
-
import {validateFunction, validateInteger} from "../types/validate.mjs";
|
10
|
+
import { Base } from "../types/base.mjs";
|
11
|
+
import { isInteger } from "../types/is.mjs";
|
12
|
+
import { validateFunction, validateInteger } from "../types/validate.mjs";
|
13
13
|
|
14
|
-
export {DeadMansSwitch}
|
14
|
+
export { DeadMansSwitch };
|
15
15
|
|
16
16
|
/**
|
17
17
|
* The dead man's switch allows to set a timer which can be reset again and again within a defined period of time.
|
@@ -23,8 +23,7 @@ export {DeadMansSwitch}
|
|
23
23
|
* @memberOf Monster.Util
|
24
24
|
* @summary Class to be able to execute function chains
|
25
25
|
*/
|
26
|
-
|
27
|
-
|
26
|
+
class DeadMansSwitch extends Base {
|
28
27
|
/**
|
29
28
|
* Create new dead man's switch
|
30
29
|
*
|
@@ -44,18 +43,17 @@ export {DeadMansSwitch}
|
|
44
43
|
* @param {Integer|undefined} [delay]
|
45
44
|
*/
|
46
45
|
touch(delay) {
|
47
|
-
|
48
|
-
|
49
|
-
throw new Error('has already run')
|
46
|
+
if (this[internalSymbol]["isAlreadyRun"] === true) {
|
47
|
+
throw new Error("has already run");
|
50
48
|
}
|
51
49
|
|
52
50
|
if (isInteger(delay)) {
|
53
|
-
this[internalSymbol][
|
51
|
+
this[internalSymbol]["delay"] = delay;
|
54
52
|
} else if (delay !== undefined) {
|
55
|
-
throw new Error(
|
53
|
+
throw new Error("unsupported argument");
|
56
54
|
}
|
57
55
|
|
58
|
-
clearTimeout(this[internalSymbol][
|
56
|
+
clearTimeout(this[internalSymbol]["timer"]);
|
59
57
|
|
60
58
|
initCallback.call(this);
|
61
59
|
|
@@ -67,13 +65,12 @@ export {DeadMansSwitch}
|
|
67
65
|
* @private
|
68
66
|
*/
|
69
67
|
function initCallback() {
|
70
|
-
|
71
68
|
const self = this;
|
72
69
|
|
73
|
-
self[internalSymbol][
|
74
|
-
self[internalSymbol][
|
75
|
-
self[internalSymbol][
|
76
|
-
}, self[internalSymbol][
|
70
|
+
self[internalSymbol]["timer"] = setTimeout(() => {
|
71
|
+
self[internalSymbol]["isAlreadyRun"] = true;
|
72
|
+
self[internalSymbol]["callback"]();
|
73
|
+
}, self[internalSymbol]["delay"]);
|
77
74
|
}
|
78
75
|
|
79
76
|
/**
|
@@ -88,12 +85,8 @@ function init(delay, callback) {
|
|
88
85
|
callback,
|
89
86
|
delay,
|
90
87
|
isAlreadyRun: false,
|
91
|
-
timer: undefined
|
88
|
+
timer: undefined,
|
92
89
|
};
|
93
90
|
|
94
91
|
initCallback.call(self);
|
95
|
-
|
96
92
|
}
|
97
|
-
|
98
|
-
|
99
|
-
|
package/source/util/freeze.mjs
CHANGED
@@ -5,9 +5,9 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {validateObject} from
|
8
|
+
import { validateObject } from "../types/validate.mjs";
|
9
9
|
|
10
|
-
export {deepFreeze}
|
10
|
+
export { deepFreeze };
|
11
11
|
|
12
12
|
/**
|
13
13
|
* Deep freeze a object
|
@@ -20,9 +20,8 @@ export {deepFreeze}
|
|
20
20
|
* @copyright schukai GmbH
|
21
21
|
* @throws {TypeError} value is not a object
|
22
22
|
*/
|
23
|
-
|
24
|
-
|
25
|
-
validateObject(object)
|
23
|
+
function deepFreeze(object) {
|
24
|
+
validateObject(object);
|
26
25
|
|
27
26
|
// Retrieve the defined property names of the object
|
28
27
|
var propNames = Object.getOwnPropertyNames(object);
|
@@ -31,8 +30,7 @@ export {deepFreeze}
|
|
31
30
|
for (let name of propNames) {
|
32
31
|
let value = object[name];
|
33
32
|
|
34
|
-
object[name] =
|
35
|
-
deepFreeze(value) : value;
|
33
|
+
object[name] = value && typeof value === "object" ? deepFreeze(value) : value;
|
36
34
|
}
|
37
35
|
|
38
36
|
return Object.freeze(object);
|
@@ -5,20 +5,19 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {internalSymbol} from "../constants.mjs";
|
9
|
-
import {Base} from "../types/base.mjs";
|
10
|
-
import {getGlobalFunction} from "../types/global.mjs";
|
11
|
-
import {isFunction, isInteger} from "../types/is.mjs";
|
12
|
-
import {Queue} from "../types/queue.mjs";
|
13
|
-
import {validateFunction, validateInteger} from "../types/validate.mjs";
|
8
|
+
import { internalSymbol } from "../constants.mjs";
|
9
|
+
import { Base } from "../types/base.mjs";
|
10
|
+
import { getGlobalFunction } from "../types/global.mjs";
|
11
|
+
import { isFunction, isInteger } from "../types/is.mjs";
|
12
|
+
import { Queue } from "../types/queue.mjs";
|
13
|
+
import { validateFunction, validateInteger } from "../types/validate.mjs";
|
14
14
|
|
15
|
-
export {Processing}
|
15
|
+
export { Processing };
|
16
16
|
|
17
17
|
/**
|
18
18
|
* @private
|
19
19
|
*/
|
20
20
|
class Callback {
|
21
|
-
|
22
21
|
/**
|
23
22
|
*
|
24
23
|
* @param {function} callback
|
@@ -30,7 +29,7 @@ class Callback {
|
|
30
29
|
constructor(callback, time) {
|
31
30
|
this[internalSymbol] = {
|
32
31
|
callback: validateFunction(callback),
|
33
|
-
time: validateInteger(time ?? 0)
|
32
|
+
time: validateInteger(time ?? 0),
|
34
33
|
};
|
35
34
|
}
|
36
35
|
|
@@ -42,20 +41,14 @@ class Callback {
|
|
42
41
|
run(data) {
|
43
42
|
const self = this;
|
44
43
|
return new Promise((resolve, reject) => {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
},
|
54
|
-
self[internalSymbol].time);
|
55
|
-
|
56
|
-
|
57
|
-
})
|
58
|
-
|
44
|
+
getGlobalFunction("setTimeout")(() => {
|
45
|
+
try {
|
46
|
+
resolve(self[internalSymbol].callback(data));
|
47
|
+
} catch (e) {
|
48
|
+
reject(e);
|
49
|
+
}
|
50
|
+
}, self[internalSymbol].time);
|
51
|
+
});
|
59
52
|
}
|
60
53
|
}
|
61
54
|
|
@@ -81,7 +74,6 @@ class Callback {
|
|
81
74
|
* @summary Class to be able to execute function chains
|
82
75
|
*/
|
83
76
|
class Processing extends Base {
|
84
|
-
|
85
77
|
/**
|
86
78
|
* Create new Processing
|
87
79
|
*
|
@@ -98,26 +90,28 @@ class Processing extends Base {
|
|
98
90
|
* @param {function} callback Callback
|
99
91
|
* @throw {TypeError} the arguments must be either integer or functions
|
100
92
|
*/
|
101
|
-
constructor() {
|
93
|
+
constructor(...args) {
|
102
94
|
super();
|
103
95
|
|
104
96
|
this[internalSymbol] = {
|
105
|
-
queue: new Queue
|
97
|
+
queue: new Queue(),
|
106
98
|
};
|
107
99
|
|
108
|
-
let time = 0
|
100
|
+
let time = 0;
|
109
101
|
|
110
|
-
|
102
|
+
if (typeof args !== "object" || args[0] === null) {
|
103
|
+
throw new TypeError("the arguments must be either integer or functions");
|
104
|
+
}
|
105
|
+
|
106
|
+
for (const [, arg] of Object.entries(args)) {
|
111
107
|
if (isInteger(arg) && arg >= 0) {
|
112
108
|
time = arg;
|
113
109
|
} else if (isFunction(arg)) {
|
114
|
-
this[internalSymbol].queue.add(new Callback(arg, time))
|
110
|
+
this[internalSymbol].queue.add(new Callback(arg, time));
|
115
111
|
} else {
|
116
|
-
throw new TypeError(
|
112
|
+
throw new TypeError("the arguments must be either integer or functions");
|
117
113
|
}
|
118
114
|
}
|
119
|
-
|
120
|
-
|
121
115
|
}
|
122
116
|
|
123
117
|
/**
|
@@ -130,11 +124,10 @@ class Processing extends Base {
|
|
130
124
|
* @throws {TypeError} value is not an integer
|
131
125
|
*/
|
132
126
|
add(callback, time) {
|
133
|
-
this[internalSymbol].queue.add(new Callback(callback, time))
|
127
|
+
this[internalSymbol].queue.add(new Callback(callback, time));
|
134
128
|
return this;
|
135
129
|
}
|
136
130
|
|
137
|
-
|
138
131
|
/**
|
139
132
|
* Executes the defined functions in order.
|
140
133
|
*
|
@@ -147,10 +140,11 @@ class Processing extends Base {
|
|
147
140
|
return Promise.resolve(data);
|
148
141
|
}
|
149
142
|
|
150
|
-
return this[internalSymbol].queue
|
151
|
-
|
152
|
-
|
153
|
-
|
143
|
+
return this[internalSymbol].queue
|
144
|
+
.poll()
|
145
|
+
.run(data)
|
146
|
+
.then((result) => {
|
147
|
+
return self.run(result);
|
148
|
+
});
|
154
149
|
}
|
155
|
-
|
156
150
|
}
|
@@ -1,5 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
/**
|
4
2
|
* Copyright schukai GmbH and contributors 2022. All Rights Reserved.
|
5
3
|
* Node module: @schukai/monster
|
@@ -7,12 +5,11 @@
|
|
7
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
8
6
|
*/
|
9
7
|
|
8
|
+
import { ID } from "../types/id.mjs";
|
9
|
+
import { isObject } from "../types/is.mjs";
|
10
|
+
import { validateString } from "../types/validate.mjs";
|
10
11
|
|
11
|
-
|
12
|
-
import {isObject} from "../types/is.mjs";
|
13
|
-
import {validateString} from "../types/validate.mjs";
|
14
|
-
|
15
|
-
export {trimSpaces}
|
12
|
+
export { trimSpaces };
|
16
13
|
|
17
14
|
/**
|
18
15
|
* This special trim function allows to trim spaces that have been protected by a special escape character.
|
@@ -23,14 +20,14 @@ export {trimSpaces}
|
|
23
20
|
* trimSpaces(' hello \\ ')
|
24
21
|
* </script>
|
25
22
|
* ```
|
26
|
-
*
|
23
|
+
*
|
27
24
|
* Hint: One stroke is escaped by the javascript interpreter, the second stroke escapes the stroke.
|
28
|
-
*
|
25
|
+
*
|
29
26
|
* ```text
|
30
27
|
* a\ b ↦ a b
|
31
28
|
* a\\ b ↦ a\ b
|
32
29
|
* ```
|
33
|
-
*
|
30
|
+
*
|
34
31
|
* @license AGPLv3
|
35
32
|
* @since 1.24.0
|
36
33
|
* @memberOf Monster.Util
|
@@ -39,40 +36,36 @@ export {trimSpaces}
|
|
39
36
|
* @return {string}
|
40
37
|
* @throws {TypeError} value is not a string
|
41
38
|
*/
|
42
|
-
|
43
|
-
|
39
|
+
function trimSpaces(value) {
|
44
40
|
validateString(value);
|
45
41
|
|
46
|
-
let placeholder = new Map;
|
47
|
-
const regex = /((?<pattern>\\(?<char>.)){1})/
|
42
|
+
let placeholder = new Map();
|
43
|
+
const regex = /((?<pattern>\\(?<char>.)){1})/gim;
|
48
44
|
|
49
45
|
// The separator for args must be escaped
|
50
46
|
// undefined string which should not occur normally and is also not a regex
|
51
|
-
let result = value.matchAll(regex)
|
47
|
+
let result = value.matchAll(regex);
|
52
48
|
|
53
49
|
for (let m of result) {
|
54
|
-
let g = m?.[
|
50
|
+
let g = m?.["groups"];
|
55
51
|
if (!isObject(g)) {
|
56
52
|
continue;
|
57
53
|
}
|
58
54
|
|
59
|
-
let p = g?.[
|
60
|
-
let c = g?.[
|
55
|
+
let p = g?.["pattern"];
|
56
|
+
let c = g?.["char"];
|
61
57
|
|
62
58
|
if (p && c) {
|
63
|
-
let r =
|
59
|
+
let r = `__${new ID().toString()}__`;
|
64
60
|
placeholder.set(r, c);
|
65
61
|
value = value.replace(p, r);
|
66
62
|
}
|
67
|
-
|
68
63
|
}
|
69
64
|
|
70
65
|
value = value.trim();
|
71
66
|
placeholder.forEach((v, k) => {
|
72
|
-
value = value.replace(k,
|
73
|
-
})
|
67
|
+
value = value.replace(k, `\\${v}`);
|
68
|
+
});
|
74
69
|
|
75
70
|
return value;
|
76
|
-
|
77
71
|
}
|
78
|
-
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
import {expect} from "chai"
|
4
4
|
|
5
|
+
import {Locale} from "../../../../application/source/i18n/locale.mjs";
|
5
6
|
import {getLocaleOfDocument} from "../../../../application/source/dom/locale.mjs";
|
6
7
|
import {initJSDOM} from "../../util/jsdom.mjs";
|
7
8
|
|
@@ -32,10 +33,24 @@ describe('Attributes', function () {
|
|
32
33
|
node.setAttribute('lang', a);
|
33
34
|
expect(getLocaleOfDocument().toString()).to.be.equal(a);
|
34
35
|
})
|
36
|
+
|
37
|
+
|
35
38
|
|
36
39
|
});
|
37
40
|
|
38
41
|
|
39
42
|
});
|
43
|
+
|
44
|
+
|
45
|
+
it('return language en', function () {
|
46
|
+
let html = document.getElementsByTagName('html');
|
47
|
+
let node = html.item(0);
|
48
|
+
|
49
|
+
node.removeAttribute('lang');
|
50
|
+
const locale = getLocaleOfDocument();
|
51
|
+
expect(locale).to.be.instanceOf(Locale);
|
52
|
+
expect(locale.localeString).to.be.equal('en-US');
|
53
|
+
})
|
54
|
+
|
40
55
|
|
41
56
|
})
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import {expect} from "chai"
|
2
|
+
|
3
|
+
|
4
|
+
import {Embed} from "../../../../../application/source/i18n/providers/embed.mjs";
|
5
|
+
import {Translations} from "../../../../../application/source/i18n/translations.mjs";
|
6
|
+
import {getGlobal} from "../../../../../application/source/types/global.mjs";
|
7
|
+
import {initJSDOM} from "../../../util/jsdom.mjs";
|
8
|
+
|
9
|
+
|
10
|
+
const global = getGlobal();
|
11
|
+
|
12
|
+
const html1 = `
|
13
|
+
<script id="templocale" type="application/json">
|
14
|
+
{
|
15
|
+
"key": "translation"
|
16
|
+
}
|
17
|
+
</script>
|
18
|
+
`;
|
19
|
+
|
20
|
+
describe('Translation Provider Embed', function () {
|
21
|
+
|
22
|
+
before(function (done) {
|
23
|
+
initJSDOM().then(() => {
|
24
|
+
done()
|
25
|
+
});
|
26
|
+
});
|
27
|
+
|
28
|
+
|
29
|
+
afterEach(() => {
|
30
|
+
let mocks = document.getElementById('mocks');
|
31
|
+
mocks.innerHTML = "";
|
32
|
+
});
|
33
|
+
|
34
|
+
beforeEach(() => {
|
35
|
+
let mocks = document.getElementById('mocks');
|
36
|
+
mocks.innerHTML = html1;
|
37
|
+
|
38
|
+
})
|
39
|
+
|
40
|
+
describe('get mock data and create translation', function () {
|
41
|
+
|
42
|
+
it('embed', function (done) {
|
43
|
+
|
44
|
+
const e = new Embed('templocale');
|
45
|
+
let p = e.getTranslations('en');
|
46
|
+
expect(p).is.instanceof(Promise);
|
47
|
+
|
48
|
+
p.then(r => {
|
49
|
+
|
50
|
+
try {
|
51
|
+
expect(r).is.instanceof(Translations);
|
52
|
+
|
53
|
+
let t = r.getText('key')
|
54
|
+
expect(t).is.equal('translation');
|
55
|
+
|
56
|
+
|
57
|
+
done();
|
58
|
+
} catch (e) {
|
59
|
+
done(e);
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
}).catch(e => {
|
64
|
+
done(e);
|
65
|
+
})
|
66
|
+
|
67
|
+
});
|
68
|
+
|
69
|
+
});
|
70
|
+
|
71
|
+
|
72
|
+
});
|
package/test/cases/monster.mjs
CHANGED