@schukai/monster 1.21.1 → 1.25.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG +48 -1
- package/README.md +4 -4
- package/dist/modules/constants.js +2 -2
- 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 +1 -1
- package/dist/modules/data/datasource/namespace.js +2 -0
- package/dist/modules/data/datasource/restapi/writeerror.js +2 -0
- package/dist/modules/data/datasource/restapi.js +2 -0
- package/dist/modules/data/datasource/storage/localstorage.js +2 -0
- package/dist/modules/data/datasource/storage/namespace.js +2 -0
- package/dist/modules/data/datasource/storage/sessionstorage.js +2 -0
- package/dist/modules/data/datasource/storage.js +2 -0
- package/dist/modules/data/datasource.js +2 -0
- package/dist/modules/data/diff.js +2 -2
- package/dist/modules/data/extend.js +1 -1
- package/dist/modules/data/namespace.js +1 -1
- package/dist/modules/data/pathfinder.js +2 -2
- package/dist/modules/data/pipe.js +1 -1
- package/dist/modules/data/transformer.js +2 -2
- 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 +2 -2
- package/dist/modules/dom/customelement.js +2 -2
- package/dist/modules/dom/events.js +1 -1
- package/dist/modules/dom/focusmanager.js +2 -0
- package/dist/modules/dom/locale.js +1 -1
- package/dist/modules/dom/namespace.js +1 -1
- package/dist/modules/dom/resource/data.js +2 -0
- package/dist/modules/dom/resource/link/stylesheet.js +2 -0
- package/dist/modules/dom/resource/link.js +2 -0
- package/dist/modules/dom/resource/script.js +2 -0
- package/dist/modules/dom/resource.js +2 -0
- package/dist/modules/dom/resourcemanager.js +2 -0
- 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 +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 +2 -2
- 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 +2 -2
- 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 +2 -2
- 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/observer.js +1 -1
- package/dist/modules/types/observerlist.js +2 -2
- package/dist/modules/types/proxyobserver.js +2 -2
- package/dist/modules/types/queue.js +1 -1
- package/dist/modules/types/randomid.js +1 -1
- package/dist/modules/types/stack.js +1 -1
- package/dist/modules/types/tokenlist.js +2 -2
- package/dist/modules/types/typeof.js +1 -1
- package/dist/modules/types/uniquequeue.js +1 -1
- package/dist/modules/types/uuid.js +2 -0
- package/dist/modules/types/validate.js +1 -1
- 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 +1 -1
- package/dist/modules/util/namespace.js +1 -1
- package/dist/modules/util/processing.js +2 -2
- package/dist/modules/util/trimspaces.js +2 -0
- package/dist/monster.dev.js +1499 -732
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +2 -2
- package/package.json +1 -1
- package/source/constants.js +16 -7
- 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 +6 -6
- package/source/data/datasource/namespace.js +16 -0
- package/source/data/datasource/restapi/writeerror.js +49 -0
- package/source/data/datasource/restapi.js +266 -0
- package/source/data/datasource/storage/localstorage.js +64 -0
- package/source/data/datasource/storage/namespace.js +16 -0
- package/source/data/datasource/storage/sessionstorage.js +61 -0
- package/source/data/datasource/storage.js +131 -0
- package/source/data/datasource.js +246 -0
- package/source/data/diff.js +8 -8
- package/source/data/extend.js +5 -5
- package/source/data/pathfinder.js +12 -6
- package/source/data/pipe.js +6 -5
- package/source/data/transformer.js +131 -24
- package/source/dom/assembler.js +2 -2
- package/source/dom/attributes.js +24 -24
- package/source/dom/constants.js +305 -12
- package/source/dom/customcontrol.js +40 -19
- package/source/dom/customelement.js +182 -103
- package/source/dom/events.js +6 -6
- package/source/dom/focusmanager.js +251 -0
- package/source/dom/locale.js +4 -3
- package/source/dom/resource/data.js +170 -0
- package/source/dom/resource/link/stylesheet.js +54 -0
- package/source/dom/resource/link.js +125 -0
- package/source/dom/resource/script.js +112 -0
- package/source/dom/resource.js +268 -0
- package/source/dom/resourcemanager.js +214 -0
- package/source/dom/template.js +40 -10
- package/source/dom/theme.js +3 -3
- package/source/dom/updater.js +114 -58
- package/source/dom/util.js +6 -6
- package/source/dom/worker/factory.js +134 -0
- package/source/i18n/locale.js +8 -8
- package/source/i18n/provider.js +4 -4
- package/source/i18n/providers/fetch.js +8 -13
- package/source/i18n/translations.js +6 -5
- 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 +4 -4
- package/source/math/random.js +11 -5
- package/source/namespace.js +1 -1
- package/source/text/formatter.js +82 -7
- package/source/types/base.js +4 -4
- package/source/types/basewithoptions.js +10 -15
- package/source/types/binary.js +8 -8
- package/source/types/dataurl.js +6 -6
- package/source/types/global.js +9 -7
- package/source/types/id.js +2 -2
- package/source/types/is.js +23 -23
- package/source/types/mediatype.js +4 -4
- package/source/types/observer.js +3 -3
- package/source/types/observerlist.js +3 -3
- package/source/types/proxyobserver.js +24 -7
- package/source/types/queue.js +5 -5
- package/source/types/randomid.js +2 -2
- package/source/types/stack.js +2 -2
- package/source/types/tokenlist.js +8 -9
- package/source/types/typeof.js +3 -3
- package/source/types/uniquequeue.js +4 -4
- package/source/types/uuid.js +102 -0
- package/source/types/validate.js +20 -20
- package/source/types/version.js +6 -6
- package/source/util/clone.js +5 -6
- package/source/util/comparator.js +5 -5
- package/source/util/freeze.js +5 -5
- package/source/util/processing.js +33 -36
- package/source/util/trimspaces.js +85 -0
- package/test/cases/data/datasource/restapi.js +89 -0
- package/test/cases/data/datasource/storage/localstorage.js +47 -0
- package/test/cases/data/datasource/storage/sessionstorage.js +47 -0
- package/test/cases/data/datasource.js +60 -0
- package/test/cases/data/diff.js +4 -4
- package/test/cases/data/pathfinder.js +18 -9
- package/test/cases/data/pipe.js +26 -2
- package/test/cases/data/transformer.js +41 -10
- package/test/cases/dom/customcontrol.js +6 -5
- package/test/cases/dom/customelement.js +25 -26
- package/test/cases/dom/focusmanager.js +111 -0
- package/test/cases/dom/locale.js +1 -4
- package/test/cases/dom/resource/data.js +129 -0
- package/test/cases/dom/resource/link/stylesheet.js +101 -0
- package/test/cases/dom/resource/link.js +101 -0
- package/test/cases/dom/resource/script.js +115 -0
- package/test/cases/dom/resourcemanager.js +118 -0
- package/test/cases/dom/updater.js +42 -19
- package/test/cases/dom/worker/factory.js +63 -0
- package/test/cases/monster.js +1 -1
- package/test/cases/text/formatter.js +38 -6
- package/test/cases/types/proxyobserver.js +55 -11
- package/test/cases/types/uuid.js +42 -0
- package/test/cases/util/freeze.js +30 -4
- package/test/cases/util/trimspaces.js +24 -0
- package/test/util/cleanupdom.js +48 -0
- package/test/util/jsdom.js +23 -9
- package/test/util/localstorage.js +81 -0
- package/test/web/import.js +13 -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 +7 -7
@@ -1,10 +1,11 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
import {PROPERTY_KEY_INTERNALDATA} from "../../constants.js";
|
4
|
-
import {extend} from "../../data/extend.js";
|
5
3
|
/**
|
6
4
|
* @author schukai GmbH
|
7
5
|
*/
|
6
|
+
|
7
|
+
import {internalSymbol} from "../../constants.js";
|
8
|
+
import {extend} from "../../data/extend.js";
|
8
9
|
import {assignToNamespace, Monster} from '../../namespace.js';
|
9
10
|
import {Formatter} from "../../text/formatter.js";
|
10
11
|
import {getGlobalFunction} from "../../types/global.js";
|
@@ -14,12 +15,6 @@ import {parseLocale} from "../locale.js";
|
|
14
15
|
import {Provider} from "../provider.js";
|
15
16
|
import {Translations} from "../translations.js";
|
16
17
|
|
17
|
-
/**
|
18
|
-
* @private
|
19
|
-
* @type {symbol}
|
20
|
-
*/
|
21
|
-
const optionsSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
22
|
-
|
23
18
|
/**
|
24
19
|
* The fetch provider retrieves a JSON file from the given URL and returns a translation object.
|
25
20
|
*
|
@@ -27,8 +22,8 @@ const optionsSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
27
22
|
*
|
28
23
|
* ```
|
29
24
|
* <script type="module">
|
30
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
31
|
-
*
|
25
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/i18n/providers/fetch.js';
|
26
|
+
* new Monster.I18n.Providers.Fetch()
|
32
27
|
* </script>
|
33
28
|
* ```
|
34
29
|
*
|
@@ -36,8 +31,8 @@ const optionsSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
36
31
|
*
|
37
32
|
* ```
|
38
33
|
* <script type="module">
|
39
|
-
* import {Fetch} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
40
|
-
*
|
34
|
+
* import {Fetch} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/i18n/providers/fetch.js';
|
35
|
+
* new Fetch()
|
41
36
|
* </script>
|
42
37
|
* ```
|
43
38
|
*
|
@@ -77,7 +72,7 @@ class Fetch extends Provider {
|
|
77
72
|
* @private
|
78
73
|
* @property {Object} options
|
79
74
|
*/
|
80
|
-
this[
|
75
|
+
this[internalSymbol] = extend({}, super.defaults, this.defaults, validateObject(options));
|
81
76
|
|
82
77
|
}
|
83
78
|
|
@@ -17,8 +17,8 @@ import {Locale, parseLocale} from "./locale.js";
|
|
17
17
|
*
|
18
18
|
* ```
|
19
19
|
* <script type="module">
|
20
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
21
|
-
*
|
20
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/i18n/translations.js';
|
21
|
+
* new Monster.I18n.Translations()
|
22
22
|
* </script>
|
23
23
|
* ```
|
24
24
|
*
|
@@ -26,13 +26,14 @@ import {Locale, parseLocale} from "./locale.js";
|
|
26
26
|
*
|
27
27
|
* ```
|
28
28
|
* <script type="module">
|
29
|
-
* import {Translations} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
30
|
-
*
|
29
|
+
* import {Translations} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/i18n/translations.js';
|
30
|
+
* new Translations()
|
31
31
|
* </script>
|
32
32
|
* ```
|
33
33
|
*
|
34
34
|
* @example
|
35
35
|
*
|
36
|
+
* import {Translations} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/i18n/translations.js';
|
36
37
|
* const translation = new Translations(parseLocale('en-GB'));
|
37
38
|
*
|
38
39
|
* translation.assignTranslations({
|
@@ -41,7 +42,7 @@ import {Locale, parseLocale} from "./locale.js";
|
|
41
42
|
* });
|
42
43
|
*
|
43
44
|
* translation.getText('text1);
|
44
|
-
* translation.getPluralRuleText('
|
45
|
+
* translation.getPluralRuleText('text2',2);
|
45
46
|
*
|
46
47
|
* @since 1.13.0
|
47
48
|
* @copyright schukai GmbH
|
@@ -15,7 +15,7 @@ import {LogEntry} from "../logentry.js";
|
|
15
15
|
*
|
16
16
|
* ```
|
17
17
|
* <script type="module">
|
18
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
18
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/logging/handler/console.js';
|
19
19
|
* console.log(new Monster.Logging.Handler.ConsoleHandler())
|
20
20
|
* </script>
|
21
21
|
* ```
|
@@ -24,7 +24,7 @@ import {LogEntry} from "../logentry.js";
|
|
24
24
|
*
|
25
25
|
* ```
|
26
26
|
* <script type="module">
|
27
|
-
* import {ConsoleHandler} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
27
|
+
* import {ConsoleHandler} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/logging/handler/console.js';
|
28
28
|
* console.log(new ConsoleHandler())
|
29
29
|
* </script>
|
30
30
|
* ```
|
@@ -15,7 +15,7 @@ import {ALL, DEBUG, ERROR, FATAL, INFO, OFF, TRACE, WARN} from "./logger.js";
|
|
15
15
|
*
|
16
16
|
* ```
|
17
17
|
* <script type="module">
|
18
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
18
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/logging/handler.js';
|
19
19
|
* console.log(new Monster.Logging.Handler())
|
20
20
|
* </script>
|
21
21
|
* ```
|
@@ -24,7 +24,7 @@ import {ALL, DEBUG, ERROR, FATAL, INFO, OFF, TRACE, WARN} from "./logger.js";
|
|
24
24
|
*
|
25
25
|
* ```
|
26
26
|
* <script type="module">
|
27
|
-
* import {ID} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
27
|
+
* import {ID} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/logging/handler.js';
|
28
28
|
* console.log(new Handler())
|
29
29
|
* </script>
|
30
30
|
* ```
|
@@ -14,7 +14,7 @@ import {validateInteger} 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.25.0/dist/modules/logging/logentry.js';
|
18
18
|
* console.log(new Monster.Logging.LogEntry())
|
19
19
|
* </script>
|
20
20
|
* ```
|
@@ -23,7 +23,7 @@ import {validateInteger} from '../types/validate.js';
|
|
23
23
|
*
|
24
24
|
* ```
|
25
25
|
* <script type="module">
|
26
|
-
* import {ID} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
26
|
+
* import {ID} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/logging/logentry.js';
|
27
27
|
* console.log(new LogEntry())
|
28
28
|
* </script>
|
29
29
|
* ```
|
package/source/logging/logger.js
CHANGED
@@ -65,8 +65,8 @@ const OFF = 0;
|
|
65
65
|
*
|
66
66
|
* ```
|
67
67
|
* <script type="module">
|
68
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
69
|
-
*
|
68
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/logging/logger.js';
|
69
|
+
* new Monster.Logging.Logger()
|
70
70
|
* </script>
|
71
71
|
* ```
|
72
72
|
*
|
@@ -74,8 +74,8 @@ const OFF = 0;
|
|
74
74
|
*
|
75
75
|
* ```
|
76
76
|
* <script type="module">
|
77
|
-
* import {ID} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
78
|
-
*
|
77
|
+
* import {ID} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/logging/logger.js';
|
78
|
+
* new Logger()
|
79
79
|
* </script>
|
80
80
|
* ```
|
81
81
|
*
|
package/source/math/random.js
CHANGED
@@ -15,8 +15,9 @@ import {getGlobal} from '../types/global.js';
|
|
15
15
|
*
|
16
16
|
* ```
|
17
17
|
* <script type="module">
|
18
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
19
|
-
*
|
18
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/math/random.js';
|
19
|
+
* Monster.Math.random(1,10)
|
20
|
+
* // ↦ 5
|
20
21
|
* </script>
|
21
22
|
* ```
|
22
23
|
*
|
@@ -24,8 +25,9 @@ import {getGlobal} from '../types/global.js';
|
|
24
25
|
*
|
25
26
|
* ```
|
26
27
|
* <script type="module">
|
27
|
-
* import {random} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
28
|
-
*
|
28
|
+
* import {random} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/math/random.js';
|
29
|
+
* random(1,10)
|
30
|
+
* // ↦ 5
|
29
31
|
* </script>
|
30
32
|
* ```
|
31
33
|
*
|
@@ -116,7 +118,11 @@ function create(min, max) {
|
|
116
118
|
return create(min, max);
|
117
119
|
}
|
118
120
|
|
119
|
-
|
121
|
+
if (rval < min) {
|
122
|
+
rval += min;
|
123
|
+
}
|
124
|
+
|
125
|
+
return rval;
|
120
126
|
|
121
127
|
}
|
122
128
|
|
package/source/namespace.js
CHANGED
@@ -65,7 +65,7 @@ export const Monster = new Namespace("Monster");
|
|
65
65
|
*
|
66
66
|
* ```
|
67
67
|
* <script type="module">
|
68
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
68
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/namespace.js';
|
69
69
|
* function hello() {
|
70
70
|
* console.log('Hello World!');
|
71
71
|
* }
|
package/source/text/formatter.js
CHANGED
@@ -18,8 +18,8 @@ import {validateObject, validateString} from "../types/validate.js";
|
|
18
18
|
*
|
19
19
|
* ```
|
20
20
|
* <script type="module">
|
21
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
22
|
-
*
|
21
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/text/formatter.js';
|
22
|
+
* new Monster.Text.Formatter()
|
23
23
|
* </script>
|
24
24
|
* ```
|
25
25
|
*
|
@@ -27,13 +27,30 @@ import {validateObject, validateString} from "../types/validate.js";
|
|
27
27
|
*
|
28
28
|
* ```
|
29
29
|
* <script type="module">
|
30
|
-
* import {Formatter} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
31
|
-
*
|
30
|
+
* import {Formatter} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/text/formatter.js';
|
31
|
+
* new Formatter()
|
32
32
|
* </script>
|
33
33
|
* ```
|
34
34
|
*
|
35
|
+
* ## Marker in marker
|
36
|
+
*
|
37
|
+
* Markers can be nested. Here, the inner marker is resolved first and then the outer marker.
|
38
|
+
*
|
39
|
+
* ```
|
40
|
+
*
|
41
|
+
* ```
|
42
|
+
*
|
43
|
+
* ## Marker with parameter
|
44
|
+
*
|
45
|
+
* A string can also bring its own values. These must then be separated from the key by a separator `::`.
|
46
|
+
* The values themselves must be specified in key/value pairs. The key must be separated from the value by a separator `=`.
|
47
|
+
*
|
48
|
+
* When using a pipe, you must pay attention to the separators.
|
49
|
+
*
|
35
50
|
* @example
|
36
51
|
*
|
52
|
+
* import {Formatter} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/text/formatter.js';
|
53
|
+
*
|
37
54
|
* new Formatter({
|
38
55
|
* a: {
|
39
56
|
* b: {
|
@@ -59,9 +76,44 @@ class Formatter extends Base {
|
|
59
76
|
*/
|
60
77
|
constructor(object) {
|
61
78
|
super();
|
79
|
+
if (object === undefined) {
|
80
|
+
object = {};
|
81
|
+
}
|
62
82
|
this.object = validateObject(object);
|
63
83
|
this.openMarker = '${';
|
64
84
|
this.closeMarker = '}';
|
85
|
+
this.parameterDelimiter = '::';
|
86
|
+
this.parameterAssignment = '=';
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Set new Parameter Character
|
91
|
+
*
|
92
|
+
* Default values for the chars are `::` and `=`
|
93
|
+
*
|
94
|
+
* ```
|
95
|
+
* formatter.setParameterChars('#');
|
96
|
+
* formatter.setParameterChars('[',']');
|
97
|
+
* formatter.setParameterChars('i18n{','}');
|
98
|
+
* ```
|
99
|
+
*
|
100
|
+
* @param {string} delimiter
|
101
|
+
* @param {string} assignment
|
102
|
+
* @return {Formatter}
|
103
|
+
* @since 1.24.0
|
104
|
+
* @throws {TypeError} value is not a string
|
105
|
+
*/
|
106
|
+
setParameterChars(delimiter, assignment) {
|
107
|
+
|
108
|
+
if (delimiter !== undefined) {
|
109
|
+
this.parameterDelimiter = validateString(delimiter);
|
110
|
+
}
|
111
|
+
|
112
|
+
if (assignment !== undefined) {
|
113
|
+
this.parameterAssignment = validateString(assignment);
|
114
|
+
}
|
115
|
+
|
116
|
+
return this;
|
65
117
|
}
|
66
118
|
|
67
119
|
/**
|
@@ -128,16 +180,39 @@ function tokenizer(text) {
|
|
128
180
|
text = text.substring(startIndex)
|
129
181
|
}
|
130
182
|
|
131
|
-
let endIndex = text.substring(self.openMarker.length).indexOf(self.closeMarker)
|
183
|
+
let endIndex = text.substring(self.openMarker.length).indexOf(self.closeMarker);
|
184
|
+
if (endIndex !== -1) endIndex += self.openMarker.length;
|
185
|
+
let insideStartIndex = text.substring(self.openMarker.length).indexOf(self.openMarker);
|
186
|
+
if (insideStartIndex !== -1) {
|
187
|
+
insideStartIndex += self.openMarker.length;
|
188
|
+
if (insideStartIndex < endIndex) {
|
189
|
+
let sub = text.substring(insideStartIndex);
|
190
|
+
let result = tokenizer.call(self, text.substring(insideStartIndex));
|
191
|
+
text = text.substring(0, insideStartIndex) + result
|
192
|
+
endIndex = text.substring(self.openMarker.length).indexOf(self.closeMarker);
|
193
|
+
if (endIndex !== -1) endIndex += self.openMarker.length;
|
194
|
+
}
|
195
|
+
}
|
196
|
+
|
132
197
|
|
133
198
|
if (endIndex === -1) {
|
134
199
|
throw new Error("syntax error in formatter template")
|
135
200
|
return;
|
136
201
|
}
|
137
202
|
|
138
|
-
let command = "path:"
|
203
|
+
let command = "path:";
|
204
|
+
let key = text.substring(self.openMarker.length, endIndex);
|
205
|
+
let parts = key.split(self.parameterDelimiter);
|
206
|
+
command += parts.shift();
|
207
|
+
|
208
|
+
const temp = self.object;
|
209
|
+
|
210
|
+
for (const kv of parts) {
|
211
|
+
const [k, v] = kv.split(self.parameterAssignment);
|
212
|
+
temp[k] = v;
|
213
|
+
}
|
139
214
|
|
140
|
-
formatted.push(validateString(new Pipe(command).run(
|
215
|
+
formatted.push(validateString(new Pipe(command).run(temp)));
|
141
216
|
|
142
217
|
text = text.substring(endIndex + self.closeMarker.length);
|
143
218
|
|
package/source/types/base.js
CHANGED
@@ -13,8 +13,8 @@ import {assignToNamespace, 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.
|
17
|
-
*
|
16
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/base.js';
|
17
|
+
* new Monster.Types.Base()
|
18
18
|
* </script>
|
19
19
|
* ```
|
20
20
|
*
|
@@ -22,8 +22,8 @@ import {assignToNamespace, Monster} from '../namespace.js';
|
|
22
22
|
*
|
23
23
|
* ```
|
24
24
|
* <script type="module">
|
25
|
-
* import {Base} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
26
|
-
*
|
25
|
+
* import {Base} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/base.js';
|
26
|
+
* new Base()
|
27
27
|
* </script>
|
28
28
|
* ```
|
29
29
|
*
|
@@ -1,21 +1,16 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
import {PROPERTY_KEY_INTERNALDATA} from "../constants.js";
|
4
|
-
import {extend} from "../data/extend.js";
|
5
|
-
import {Pathfinder} from "../data/pathfinder.js";
|
6
3
|
/**
|
7
4
|
* @author schukai GmbH
|
8
5
|
*/
|
6
|
+
|
7
|
+
import {internalSymbol} from "../constants.js";
|
8
|
+
import {extend} from "../data/extend.js";
|
9
|
+
import {Pathfinder} from "../data/pathfinder.js";
|
9
10
|
import {assignToNamespace, Monster} from '../namespace.js';
|
10
11
|
import {Base} from "./base.js";
|
11
12
|
import {validateObject} from "./validate.js";
|
12
13
|
|
13
|
-
/**
|
14
|
-
* @private
|
15
|
-
* @type {symbol}
|
16
|
-
*/
|
17
|
-
const optionsSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
18
|
-
|
19
14
|
/**
|
20
15
|
* This is the base class with options from which some monster classes are derived.
|
21
16
|
*
|
@@ -23,8 +18,8 @@ const optionsSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
23
18
|
*
|
24
19
|
* ```
|
25
20
|
* <script type="module">
|
26
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
27
|
-
*
|
21
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/basewithoptions.js';
|
22
|
+
* new Monster.Types.BaseWithOptions()
|
28
23
|
* </script>
|
29
24
|
* ```
|
30
25
|
*
|
@@ -32,8 +27,8 @@ const optionsSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
32
27
|
*
|
33
28
|
* ```
|
34
29
|
* <script type="module">
|
35
|
-
* import {BaseWithOptions} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
36
|
-
*
|
30
|
+
* import {BaseWithOptions} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/basewithoptions.js';
|
31
|
+
* new BaseWithOptions()
|
37
32
|
* </script>
|
38
33
|
* ```
|
39
34
|
*
|
@@ -56,7 +51,7 @@ class BaseWithOptions extends Base {
|
|
56
51
|
options = {};
|
57
52
|
}
|
58
53
|
|
59
|
-
this[
|
54
|
+
this[internalSymbol] = extend({}, this.defaults, validateObject(options));
|
60
55
|
|
61
56
|
}
|
62
57
|
|
@@ -81,7 +76,7 @@ class BaseWithOptions extends Base {
|
|
81
76
|
let value;
|
82
77
|
|
83
78
|
try {
|
84
|
-
value = new Pathfinder(this[
|
79
|
+
value = new Pathfinder(this[internalSymbol]).getVia(path);
|
85
80
|
} catch (e) {
|
86
81
|
|
87
82
|
}
|
package/source/types/binary.js
CHANGED
@@ -13,8 +13,8 @@ import {Monster, validateString} from "./validate.js";
|
|
13
13
|
*
|
14
14
|
* ```
|
15
15
|
* <script type="module">
|
16
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
17
|
-
*
|
16
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/binary.js';
|
17
|
+
* Monster.Types.toBinary()
|
18
18
|
* </script>
|
19
19
|
* ```
|
20
20
|
*
|
@@ -22,8 +22,8 @@ import {Monster, validateString} from "./validate.js";
|
|
22
22
|
*
|
23
23
|
* ```
|
24
24
|
* <script type="module">
|
25
|
-
* import {toBinary} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
26
|
-
*
|
25
|
+
* import {toBinary} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/binary.js';
|
26
|
+
* toBinary()
|
27
27
|
* </script>
|
28
28
|
* ```
|
29
29
|
*
|
@@ -54,8 +54,8 @@ function toBinary(string) {
|
|
54
54
|
*
|
55
55
|
* ```
|
56
56
|
* <script type="module">
|
57
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
58
|
-
*
|
57
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/binary.js';
|
58
|
+
* Monster.Types.fromBinary()
|
59
59
|
* </script>
|
60
60
|
* ```
|
61
61
|
*
|
@@ -63,8 +63,8 @@ function toBinary(string) {
|
|
63
63
|
*
|
64
64
|
* ```
|
65
65
|
* <script type="module">
|
66
|
-
* import {fromBinary} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
67
|
-
*
|
66
|
+
* import {fromBinary} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/binary.js';
|
67
|
+
* fromBinary()
|
68
68
|
* </script>
|
69
69
|
* ```
|
70
70
|
*
|
package/source/types/dataurl.js
CHANGED
@@ -20,8 +20,8 @@ const internal = Symbol('internal');
|
|
20
20
|
*
|
21
21
|
* ```
|
22
22
|
* <script type="module">
|
23
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
24
|
-
*
|
23
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/dataurl.js';
|
24
|
+
* new Monster.Types.DataUrl()
|
25
25
|
* </script>
|
26
26
|
* ```
|
27
27
|
*
|
@@ -29,8 +29,8 @@ const internal = Symbol('internal');
|
|
29
29
|
*
|
30
30
|
* ```
|
31
31
|
* <script type="module">
|
32
|
-
* import {DataUrl} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
33
|
-
*
|
32
|
+
* import {DataUrl} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/dataurl.js';
|
33
|
+
* new DataUrl()
|
34
34
|
* </script>
|
35
35
|
* ```
|
36
36
|
*
|
@@ -98,7 +98,7 @@ class DataUrl extends Base {
|
|
98
98
|
*
|
99
99
|
* ```
|
100
100
|
* <script type="module">
|
101
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
101
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/dataurl.js';
|
102
102
|
* console.log(Monster.Types.parseDataURL())
|
103
103
|
* </script>
|
104
104
|
* ```
|
@@ -107,7 +107,7 @@ class DataUrl extends Base {
|
|
107
107
|
*
|
108
108
|
* ```
|
109
109
|
* <script type="module">
|
110
|
-
* import {parseDataURL} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
110
|
+
* import {parseDataURL} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/dataurl.js';
|
111
111
|
* console.log(parseDataURL())
|
112
112
|
* </script>
|
113
113
|
* ```
|
package/source/types/global.js
CHANGED
@@ -78,8 +78,9 @@ function getGlobal() {
|
|
78
78
|
*
|
79
79
|
* ```
|
80
80
|
* <script type="module">
|
81
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
82
|
-
*
|
81
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/global.js';
|
82
|
+
* Monster.Types.getGlobalObject('document')
|
83
|
+
* // ↦ { }
|
83
84
|
* </script>
|
84
85
|
* ```
|
85
86
|
*
|
@@ -87,8 +88,9 @@ function getGlobal() {
|
|
87
88
|
*
|
88
89
|
* ```
|
89
90
|
* <script type="module">
|
90
|
-
* import {getGlobalObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
91
|
-
*
|
91
|
+
* import {getGlobalObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/global.js';
|
92
|
+
* getGlobalObject('document')
|
93
|
+
* // ↦ { }
|
92
94
|
* </script>
|
93
95
|
* ```
|
94
96
|
*
|
@@ -115,7 +117,7 @@ function getGlobalObject(name) {
|
|
115
117
|
*
|
116
118
|
* ```
|
117
119
|
* <script type="module">
|
118
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
120
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/global.js';
|
119
121
|
* console.log(Monster.Types.getGlobalFunction('parseInt')) // ↦ f parseInt() { }
|
120
122
|
* </script>
|
121
123
|
* ```
|
@@ -124,7 +126,7 @@ function getGlobalObject(name) {
|
|
124
126
|
*
|
125
127
|
* ```
|
126
128
|
* <script type="module">
|
127
|
-
* import {getGlobalFunction} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
129
|
+
* import {getGlobalFunction} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/types/global.js';
|
128
130
|
* console.log(getGlobalFunction('parseInt')) // ↦ f parseInt() { }
|
129
131
|
* </script>
|
130
132
|
* ```
|
@@ -132,7 +134,7 @@ function getGlobalObject(name) {
|
|
132
134
|
* @since 1.6.0
|
133
135
|
* @memberOf Monster.Types
|
134
136
|
* @param {string} name
|
135
|
-
* @
|
137
|
+
* @return {objec}
|
136
138
|
* @throws {TypeError} value is not a function
|
137
139
|
* @throws {Error} the function is not defined
|
138
140
|
* @throws {TypeError} value is not a string
|
package/source/types/id.js
CHANGED
@@ -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.25.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.25.0/dist/modules/types/id.js';
|
37
37
|
* console.log(new ID())
|
38
38
|
* </script>
|
39
39
|
* ```
|