@schukai/monster 1.25.0 → 1.26.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG +15 -0
- package/README.md +3 -3
- package/dist/modules/constants.js +1 -1
- package/dist/modules/constraints/abstract.js +1 -1
- package/dist/modules/constraints/abstractoperator.js +1 -1
- package/dist/modules/constraints/andoperator.js +1 -1
- package/dist/modules/constraints/invalid.js +1 -1
- package/dist/modules/constraints/isarray.js +1 -1
- package/dist/modules/constraints/isobject.js +1 -1
- package/dist/modules/constraints/namespace.js +1 -1
- package/dist/modules/constraints/oroperator.js +1 -1
- package/dist/modules/constraints/valid.js +1 -1
- package/dist/modules/data/buildmap.js +2 -2
- package/dist/modules/data/buildtree.js +2 -0
- package/dist/modules/data/datasource/namespace.js +1 -1
- package/dist/modules/data/datasource/restapi/writeerror.js +1 -1
- package/dist/modules/data/datasource/restapi.js +1 -1
- package/dist/modules/data/datasource/storage/localstorage.js +1 -1
- package/dist/modules/data/datasource/storage/namespace.js +1 -1
- package/dist/modules/data/datasource/storage/sessionstorage.js +1 -1
- package/dist/modules/data/datasource/storage.js +1 -1
- package/dist/modules/data/datasource.js +1 -1
- package/dist/modules/data/diff.js +1 -1
- package/dist/modules/data/extend.js +1 -1
- package/dist/modules/data/namespace.js +1 -1
- package/dist/modules/data/pathfinder.js +1 -1
- package/dist/modules/data/pipe.js +1 -1
- package/dist/modules/data/transformer.js +1 -1
- package/dist/modules/dom/assembler.js +1 -1
- package/dist/modules/dom/attributes.js +1 -1
- package/dist/modules/dom/constants.js +1 -1
- package/dist/modules/dom/customcontrol.js +1 -1
- package/dist/modules/dom/customelement.js +1 -1
- package/dist/modules/dom/events.js +1 -1
- package/dist/modules/dom/focusmanager.js +1 -1
- package/dist/modules/dom/locale.js +1 -1
- package/dist/modules/dom/namespace.js +1 -1
- package/dist/modules/dom/resource/data.js +1 -1
- package/dist/modules/dom/resource/link/stylesheet.js +1 -1
- package/dist/modules/dom/resource/link.js +1 -1
- package/dist/modules/dom/resource/script.js +1 -1
- package/dist/modules/dom/resource.js +1 -1
- package/dist/modules/dom/resourcemanager.js +1 -1
- package/dist/modules/dom/template.js +1 -1
- package/dist/modules/dom/theme.js +1 -1
- package/dist/modules/dom/updater.js +2 -2
- package/dist/modules/dom/util.js +1 -1
- package/dist/modules/dom/worker/factory.js +1 -1
- package/dist/modules/i18n/formatter.js +2 -0
- package/dist/modules/i18n/locale.js +1 -1
- package/dist/modules/i18n/namespace.js +1 -1
- package/dist/modules/i18n/provider.js +1 -1
- package/dist/modules/i18n/providers/fetch.js +1 -1
- package/dist/modules/i18n/providers/namespace.js +1 -1
- package/dist/modules/i18n/translations.js +1 -1
- package/dist/modules/logging/handler/console.js +1 -1
- package/dist/modules/logging/handler/namespace.js +1 -1
- package/dist/modules/logging/handler.js +1 -1
- package/dist/modules/logging/logentry.js +1 -1
- package/dist/modules/logging/logger.js +1 -1
- package/dist/modules/logging/namespace.js +1 -1
- package/dist/modules/math/namespace.js +1 -1
- package/dist/modules/math/random.js +1 -1
- package/dist/modules/monster.js +1 -1
- package/dist/modules/namespace.js +1 -1
- package/dist/modules/text/formatter.js +2 -2
- package/dist/modules/text/namespace.js +1 -1
- package/dist/modules/types/base.js +1 -1
- package/dist/modules/types/basewithoptions.js +1 -1
- package/dist/modules/types/binary.js +1 -1
- package/dist/modules/types/dataurl.js +1 -1
- package/dist/modules/types/global.js +1 -1
- package/dist/modules/types/id.js +1 -1
- package/dist/modules/types/is.js +2 -2
- package/dist/modules/types/mediatype.js +1 -1
- package/dist/modules/types/namespace.js +1 -1
- package/dist/modules/types/node.js +2 -0
- package/dist/modules/types/nodelist.js +2 -0
- package/dist/modules/types/noderecursiveiterator.js +2 -0
- package/dist/modules/types/observer.js +1 -1
- package/dist/modules/types/observerlist.js +1 -1
- package/dist/modules/types/proxyobserver.js +1 -1
- package/dist/modules/types/queue.js +1 -1
- package/dist/modules/types/randomid.js +1 -1
- package/dist/modules/types/regex.js +2 -0
- package/dist/modules/types/stack.js +1 -1
- package/dist/modules/types/tokenlist.js +1 -1
- package/dist/modules/types/typeof.js +1 -1
- package/dist/modules/types/uniquequeue.js +1 -1
- package/dist/modules/types/uuid.js +1 -1
- package/dist/modules/types/validate.js +1 -1
- package/dist/modules/types/version.js +2 -2
- package/dist/modules/util/clone.js +1 -1
- package/dist/modules/util/comparator.js +1 -1
- package/dist/modules/util/freeze.js +1 -1
- package/dist/modules/util/namespace.js +1 -1
- package/dist/modules/util/processing.js +1 -1
- package/dist/modules/util/trimspaces.js +1 -1
- package/dist/monster.dev.js +620 -361
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +2 -2
- package/package.json +13 -2
- package/source/constraints/abstract.js +5 -0
- package/source/constraints/abstractoperator.js +5 -0
- package/source/constraints/andoperator.js +10 -5
- package/source/constraints/invalid.js +8 -3
- package/source/constraints/isarray.js +9 -4
- package/source/constraints/isobject.js +8 -3
- package/source/constraints/oroperator.js +10 -5
- package/source/constraints/valid.js +8 -3
- package/source/data/buildmap.js +25 -9
- package/source/data/buildtree.js +95 -0
- package/source/data/datasource/restapi.js +3 -3
- package/source/data/datasource/storage/localstorage.js +2 -2
- package/source/data/datasource/storage/sessionstorage.js +2 -2
- package/source/data/datasource/storage.js +3 -3
- package/source/data/datasource.js +3 -3
- package/source/data/diff.js +3 -3
- package/source/data/extend.js +2 -2
- package/source/data/pathfinder.js +4 -4
- package/source/data/pipe.js +3 -3
- package/source/data/transformer.js +3 -3
- package/source/dom/assembler.js +2 -2
- package/source/dom/attributes.js +24 -24
- package/source/dom/customcontrol.js +1 -1
- package/source/dom/customelement.js +1 -1
- package/source/dom/events.js +4 -4
- package/source/dom/focusmanager.js +6 -7
- package/source/dom/locale.js +8 -4
- package/source/dom/resource/data.js +2 -2
- package/source/dom/resource/link/stylesheet.js +2 -2
- package/source/dom/resource/link.js +2 -2
- package/source/dom/resource/script.js +2 -2
- package/source/dom/resource.js +2 -2
- package/source/dom/resourcemanager.js +2 -2
- package/source/dom/template.js +5 -5
- package/source/dom/theme.js +3 -3
- package/source/dom/updater.js +5 -5
- package/source/dom/util.js +6 -6
- package/source/dom/worker/factory.js +2 -2
- package/source/i18n/formatter.js +140 -0
- package/source/i18n/locale.js +6 -4
- package/source/i18n/provider.js +2 -2
- package/source/i18n/providers/fetch.js +18 -3
- package/source/i18n/translations.js +18 -9
- package/source/logging/handler/console.js +2 -2
- package/source/logging/handler.js +2 -2
- package/source/logging/logentry.js +2 -2
- package/source/logging/logger.js +2 -2
- package/source/math/random.js +2 -2
- package/source/namespace.js +1 -1
- package/source/text/formatter.js +190 -48
- package/source/types/base.js +2 -2
- package/source/types/basewithoptions.js +2 -2
- package/source/types/binary.js +4 -4
- package/source/types/dataurl.js +4 -4
- package/source/types/global.js +4 -4
- package/source/types/id.js +6 -3
- package/source/types/is.js +100 -82
- package/source/types/mediatype.js +4 -4
- package/source/types/node.js +179 -0
- package/source/types/nodelist.js +125 -0
- package/source/types/noderecursiveiterator.js +126 -0
- package/source/types/observer.js +3 -3
- package/source/types/observerlist.js +2 -2
- package/source/types/proxyobserver.js +5 -5
- package/source/types/queue.js +4 -4
- package/source/types/randomid.js +2 -2
- package/source/types/regex.js +49 -0
- package/source/types/stack.js +2 -2
- package/source/types/tokenlist.js +2 -2
- package/source/types/typeof.js +3 -3
- package/source/types/uniquequeue.js +2 -2
- package/source/types/uuid.js +2 -2
- package/source/types/validate.js +20 -20
- package/source/types/version.js +6 -6
- package/source/util/clone.js +2 -2
- package/source/util/comparator.js +3 -3
- package/source/util/freeze.js +2 -2
- package/source/util/processing.js +3 -3
- package/source/util/trimspaces.js +2 -2
- package/test/cases/data/buildtree.js +149 -0
- package/test/cases/dom/attributes.js +18 -14
- package/test/cases/dom/resource/link/stylesheet.js +1 -1
- package/test/cases/i18n/formatter.js +66 -0
- package/test/cases/monster.js +1 -1
- package/test/cases/text/formatter.js +36 -5
- package/test/cases/types/node.js +196 -0
- package/test/cases/types/nodelist.js +64 -0
- package/test/cases/types/noderecursiveiterator.js +54 -0
- package/test/cases/types/regex.js +32 -0
- package/test/util/jsdom.js +0 -1
- package/test/web/import.js +6 -0
- package/test/web/monster-dev.html +3 -3
- package/test/web/monster.html +2 -2
- package/test/web/test.html +2 -2
- package/test/web/tests.js +3 -3
package/source/dom/theme.js
CHANGED
@@ -15,7 +15,7 @@ import {ATTRIBUTE_THEME_NAME, DEFAULT_THEME} from "./constants.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.26.0/dist/monster.js';
|
19
19
|
* console.log(new Monster.DOM.Theme())
|
20
20
|
* </script>
|
21
21
|
* ```
|
@@ -24,14 +24,14 @@ import {ATTRIBUTE_THEME_NAME, DEFAULT_THEME} from "./constants.js";
|
|
24
24
|
*
|
25
25
|
* ```
|
26
26
|
* <script type="module">
|
27
|
-
* import {Theme} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
27
|
+
* import {Theme} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/theme.js';
|
28
28
|
* console.log(new Theme())
|
29
29
|
* </script>
|
30
30
|
* ```
|
31
31
|
*
|
32
32
|
* @example
|
33
33
|
*
|
34
|
-
* import {getDocumentTheme} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
34
|
+
* import {getDocumentTheme} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/theme.js';
|
35
35
|
*
|
36
36
|
* const theme = getDocumentTheme();
|
37
37
|
* console.log(theme.getName());
|
package/source/dom/updater.js
CHANGED
@@ -38,7 +38,7 @@ import {getDocument} from "./util.js";
|
|
38
38
|
*
|
39
39
|
* ```
|
40
40
|
* <script type="module">
|
41
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
41
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
42
42
|
* new Monster.DOM.Updater()
|
43
43
|
* </script>
|
44
44
|
* ```
|
@@ -47,14 +47,14 @@ import {getDocument} from "./util.js";
|
|
47
47
|
*
|
48
48
|
* ```
|
49
49
|
* <script type="module">
|
50
|
-
* import {Updater} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
50
|
+
* import {Updater} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/updater.js';
|
51
51
|
* new Updater()
|
52
52
|
* </script>
|
53
53
|
* ```
|
54
54
|
*
|
55
55
|
* @example
|
56
56
|
*
|
57
|
-
* import {Updater} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
57
|
+
* import {Updater} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/updater.js';
|
58
58
|
*
|
59
59
|
* // First we prepare the html document.
|
60
60
|
* // This is done here via script, but can also be inserted into the document as pure html.
|
@@ -530,12 +530,12 @@ function applyRecursive(node, key, path) {
|
|
530
530
|
|
531
531
|
if (node.hasAttribute(ATTRIBUTE_UPDATER_REPLACE)) {
|
532
532
|
let value = node.getAttribute(ATTRIBUTE_UPDATER_REPLACE);
|
533
|
-
node.setAttribute(ATTRIBUTE_UPDATER_REPLACE, value.
|
533
|
+
node.setAttribute(ATTRIBUTE_UPDATER_REPLACE, value.replaceAll("path:" + key, "path:" + path));
|
534
534
|
}
|
535
535
|
|
536
536
|
if (node.hasAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES)) {
|
537
537
|
let value = node.getAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES);
|
538
|
-
node.setAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES, value.
|
538
|
+
node.setAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES, value.replaceAll("path:" + key, "path:" + path));
|
539
539
|
}
|
540
540
|
|
541
541
|
for (const [, child] of Object.entries(node.childNodes)) {
|
package/source/dom/util.js
CHANGED
@@ -13,7 +13,7 @@ import {validateString} from "../types/validate.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.26.0/dist/monster.js';
|
17
17
|
* console.log(Monster.DOM.getDocument())
|
18
18
|
* </script>
|
19
19
|
* ```
|
@@ -22,7 +22,7 @@ import {validateString} from "../types/validate.js";
|
|
22
22
|
*
|
23
23
|
* ```
|
24
24
|
* <script type="module">
|
25
|
-
* import {getDocument} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
25
|
+
* import {getDocument} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/util.js';
|
26
26
|
* console.log(getDocument())
|
27
27
|
* </script>
|
28
28
|
* ```
|
@@ -74,7 +74,7 @@ function getDocument() {
|
|
74
74
|
*
|
75
75
|
* ```
|
76
76
|
* <script type="module">
|
77
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
77
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
78
78
|
* console.log(Monster.DOM.getWindow())
|
79
79
|
* </script>
|
80
80
|
* ```
|
@@ -83,7 +83,7 @@ function getDocument() {
|
|
83
83
|
*
|
84
84
|
* ```
|
85
85
|
* <script type="module">
|
86
|
-
* import {getWindow} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
86
|
+
* import {getWindow} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/util.js';
|
87
87
|
* console.log(getWindow(null))
|
88
88
|
* </script>
|
89
89
|
* ```
|
@@ -140,7 +140,7 @@ function getWindow() {
|
|
140
140
|
*
|
141
141
|
* ```
|
142
142
|
* <script type="module">
|
143
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
143
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
144
144
|
* console.log(Monster.DOM.getDocumentFragmentFromString())
|
145
145
|
* </script>
|
146
146
|
* ```
|
@@ -149,7 +149,7 @@ function getWindow() {
|
|
149
149
|
*
|
150
150
|
* ```
|
151
151
|
* <script type="module">
|
152
|
-
* import {getDocumentFragmentFromString} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
152
|
+
* import {getDocumentFragmentFromString} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/util.js';
|
153
153
|
* console.log(getDocumentFragmentFromString('<div></div>'))
|
154
154
|
* </script>
|
155
155
|
* ```
|
@@ -20,7 +20,7 @@ import {validateInstance, validateString} from "../../types/validate.js";
|
|
20
20
|
*
|
21
21
|
* ```
|
22
22
|
* <script type="module">
|
23
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
23
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
24
24
|
* console.log(new Monster.DOM.Worker.Factory())
|
25
25
|
* </script>
|
26
26
|
* ```
|
@@ -29,7 +29,7 @@ import {validateInstance, validateString} from "../../types/validate.js";
|
|
29
29
|
*
|
30
30
|
* ```
|
31
31
|
* <script type="module">
|
32
|
-
* import {Factory} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
32
|
+
* import {Factory} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/dom/worker/factory.js';
|
33
33
|
* console.log(new Factory())
|
34
34
|
* </script>
|
35
35
|
* ```
|
@@ -0,0 +1,140 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @author schukai GmbH
|
5
|
+
*/
|
6
|
+
|
7
|
+
|
8
|
+
import {internalSymbol} from "../constants.js";
|
9
|
+
import {extend} from "../data/extend.js";
|
10
|
+
import {assignToNamespace, Monster} from '../namespace.js';
|
11
|
+
import {Formatter as TextFormatter} from "../text/formatter.js";
|
12
|
+
import {validateInstance, validateString} from "../types/validate.js";
|
13
|
+
import {Translations} from "./translations.js";
|
14
|
+
|
15
|
+
/**
|
16
|
+
* @private
|
17
|
+
* @type {symbol}
|
18
|
+
*/
|
19
|
+
const internalTranslationSymbol = Symbol('internalTranslation')
|
20
|
+
|
21
|
+
/**
|
22
|
+
* The Formatter extends the Text.Formatter with the possibility to replace the key by a translation.
|
23
|
+
*
|
24
|
+
* You can create an instance via the monster namespace `new Monster.I18n.Formatter()`.
|
25
|
+
*
|
26
|
+
* ```
|
27
|
+
* <script type="module">
|
28
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
29
|
+
* new Monster.I18n.Formatter()
|
30
|
+
* </script>
|
31
|
+
* ```
|
32
|
+
*
|
33
|
+
* Alternatively, you can also integrate this function individually.
|
34
|
+
*
|
35
|
+
* ```
|
36
|
+
* <script type="module">
|
37
|
+
* import {Formatter} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/i18n/formatter.js';
|
38
|
+
* new Formatter()
|
39
|
+
* </script>
|
40
|
+
* ```
|
41
|
+
*
|
42
|
+
* @example
|
43
|
+
*
|
44
|
+
* import {Formatter} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/i18n/formatter.js';
|
45
|
+
* import {Translations} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/i18n/translations.js';
|
46
|
+
*
|
47
|
+
* const translations = new Translations('en')
|
48
|
+
* .assignTranslations({
|
49
|
+
* thekey: "${animal} has eaten the ${food}!"
|
50
|
+
* });
|
51
|
+
*
|
52
|
+
* new Formatter({}, translations).format("thekey:animal=dog::food=cake")
|
53
|
+
* // ↦ dog has eaten the cake!
|
54
|
+
*
|
55
|
+
* @since 1.26.0
|
56
|
+
* @copyright schukai GmbH
|
57
|
+
* @memberOf Monster.I18n
|
58
|
+
*/
|
59
|
+
class Formatter extends TextFormatter {
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Default values for the markers are `${` and `}`
|
63
|
+
*
|
64
|
+
* @param {object} object
|
65
|
+
* @throws {TypeError} value is not a object
|
66
|
+
*/
|
67
|
+
constructor(object, translation, options) {
|
68
|
+
super(object, options);
|
69
|
+
this[internalTranslationSymbol] = validateInstance(translation, Translations);
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* @property {object} marker
|
74
|
+
* @property {array} marker.open=["i18n{","${"]
|
75
|
+
* @property {array} marker.close=["${"]
|
76
|
+
* @property {object} parameter
|
77
|
+
* @property {string} parameter.delimiter="::"
|
78
|
+
* @property {string} parameter.assignment="="
|
79
|
+
* @property {object} callbacks
|
80
|
+
* @property {function} callbacks.i18n=()=>{}
|
81
|
+
*/
|
82
|
+
get defaults() {
|
83
|
+
const self = this;
|
84
|
+
return extend({}, super.defaults, {
|
85
|
+
callbacks: {
|
86
|
+
i18n: (value) => {
|
87
|
+
return self[internalTranslationSymbol].getText(validateString(value));
|
88
|
+
}
|
89
|
+
},
|
90
|
+
marker: {
|
91
|
+
open: ['i18n{', '${'],
|
92
|
+
close: ['}'],
|
93
|
+
},
|
94
|
+
})
|
95
|
+
}
|
96
|
+
|
97
|
+
/**
|
98
|
+
*
|
99
|
+
* @param {string} text
|
100
|
+
* @return {string}
|
101
|
+
* @throws {TypeError} value is not a string
|
102
|
+
* @throws {Error} too deep nesting
|
103
|
+
* @throws {Error} key not found
|
104
|
+
* @throws {Error} the closing marker is missing
|
105
|
+
*/
|
106
|
+
format(text) {
|
107
|
+
validateString(text)
|
108
|
+
|
109
|
+
const openMarker = this[internalSymbol]['marker']['open']?.[0];
|
110
|
+
const closeMarker = this[internalSymbol]['marker']['close']?.[0];
|
111
|
+
|
112
|
+
if (text.indexOf(openMarker) === 0) {
|
113
|
+
text = text.substring(openMarker.length);
|
114
|
+
|
115
|
+
if (text.indexOf(closeMarker) === text.length - closeMarker.length) {
|
116
|
+
text = text.substring(0, text.length - closeMarker.length);
|
117
|
+
} else {
|
118
|
+
throw new Error("the closing marker is missing")
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
|
123
|
+
const parts = validateString(text).split('::')
|
124
|
+
const translationKey = parts.shift().trim(); // key value delimiter
|
125
|
+
const parameter = parts.join('::').trim();
|
126
|
+
|
127
|
+
|
128
|
+
let assembledText = openMarker + 'static:' + translationKey + ' | call:i18n';
|
129
|
+
if (parameter.length > 0) {
|
130
|
+
assembledText += '::' + parameter;
|
131
|
+
}
|
132
|
+
assembledText += closeMarker;
|
133
|
+
return super.format(assembledText);
|
134
|
+
}
|
135
|
+
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
assignToNamespace('Monster.I18n', Formatter);
|
140
|
+
export {Monster, Formatter}
|
package/source/i18n/locale.js
CHANGED
@@ -25,7 +25,7 @@ const localeStringSymbol = Symbol('localeString');
|
|
25
25
|
*
|
26
26
|
* ```
|
27
27
|
* <script type="module">
|
28
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
28
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
29
29
|
* new Monster.I18n.Locale()
|
30
30
|
* </script>
|
31
31
|
* ```
|
@@ -34,7 +34,7 @@ const localeStringSymbol = Symbol('localeString');
|
|
34
34
|
*
|
35
35
|
* ```
|
36
36
|
* <script type="module">
|
37
|
-
* import {Locale} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
37
|
+
* import {Locale} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/i18n/locale.js';
|
38
38
|
* new Locale()
|
39
39
|
* </script>
|
40
40
|
* ```
|
@@ -172,6 +172,8 @@ class Locale extends Base {
|
|
172
172
|
}
|
173
173
|
|
174
174
|
/**
|
175
|
+
* The structure has the following: language, script, region, variants, extlang, privateUse
|
176
|
+
*
|
175
177
|
* @return {Monster.I18n.LocaleMap}
|
176
178
|
*/
|
177
179
|
getMap() {
|
@@ -201,7 +203,7 @@ class Locale extends Base {
|
|
201
203
|
*
|
202
204
|
* ```
|
203
205
|
* <script type="module">
|
204
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
206
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
205
207
|
* new Monster.I18n.createLocale()
|
206
208
|
* </script>
|
207
209
|
* ```
|
@@ -210,7 +212,7 @@ class Locale extends Base {
|
|
210
212
|
*
|
211
213
|
* ```
|
212
214
|
* <script type="module">
|
213
|
-
* import {createLocale} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
215
|
+
* import {createLocale} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/i18n/locale.js';
|
214
216
|
* createLocale()
|
215
217
|
* </script>
|
216
218
|
* ```
|
package/source/i18n/provider.js
CHANGED
@@ -15,7 +15,7 @@ import {Translations} from "./translations.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.26.0/dist/monster.js';
|
19
19
|
* new Monster.I18n.Provider()
|
20
20
|
* </script>
|
21
21
|
* ```
|
@@ -24,7 +24,7 @@ import {Translations} from "./translations.js"
|
|
24
24
|
*
|
25
25
|
* ```
|
26
26
|
* <script type="module">
|
27
|
-
* import {Provider} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
27
|
+
* import {Provider} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/i18n/provider.js';
|
28
28
|
* new Provider()
|
29
29
|
* </script>
|
30
30
|
* ```
|
@@ -22,7 +22,7 @@ import {Translations} from "../translations.js";
|
|
22
22
|
*
|
23
23
|
* ```
|
24
24
|
* <script type="module">
|
25
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
25
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
26
26
|
* new Monster.I18n.Providers.Fetch()
|
27
27
|
* </script>
|
28
28
|
* ```
|
@@ -31,21 +31,36 @@ import {Translations} from "../translations.js";
|
|
31
31
|
*
|
32
32
|
* ```
|
33
33
|
* <script type="module">
|
34
|
-
* import {Fetch} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
34
|
+
* import {Fetch} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/i18n/providers/fetch.js';
|
35
35
|
* new Fetch()
|
36
36
|
* </script>
|
37
37
|
* ```
|
38
|
+
*
|
39
|
+
* @example <caption>das ist ein test</caption>
|
40
|
+
*
|
41
|
+
* import {Fetch} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/i18n/providers/fetch.js';
|
42
|
+
*
|
43
|
+
* // fetch from API
|
44
|
+
* const translation = new Fetch('https://example.com/${language}.json').getTranslation('en-GB');
|
45
|
+
* // ↦ https://example.com/en.json
|
38
46
|
*
|
39
47
|
* @since 1.13.0
|
40
48
|
* @copyright schukai GmbH
|
41
49
|
* @memberOf Monster.I18n.Providers
|
42
50
|
* @see {@link https://datatracker.ietf.org/doc/html/rfc3066}
|
51
|
+
* @tutorial i18n-locale-and-formatter
|
43
52
|
*/
|
44
53
|
class Fetch extends Provider {
|
45
54
|
|
46
55
|
/**
|
47
56
|
* As options the key `fetch` can be passed. This config object is passed to the fetch method as init.
|
48
|
-
*
|
57
|
+
*
|
58
|
+
* The url may contain placeholders (language, script, region, variants, extlang, privateUse), so you can specify one url for all translations.
|
59
|
+
*
|
60
|
+
* ```
|
61
|
+
* new Fetch('https://www.example.com/assets/${language}.json')
|
62
|
+
* ```
|
63
|
+
*
|
49
64
|
* @param {string|URL} url
|
50
65
|
* @param {Object} options see {@link Monster.I18n.Providers.Fetch#defaults}
|
51
66
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}
|
@@ -17,7 +17,7 @@ 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.
|
20
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
21
21
|
* new Monster.I18n.Translations()
|
22
22
|
* </script>
|
23
23
|
* ```
|
@@ -26,23 +26,33 @@ 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.
|
29
|
+
* import {Translations} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/i18n/translations.js';
|
30
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.
|
36
|
+
* import {Translations} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/i18n/translations.js';
|
37
|
+
* import {parseLocale} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/i18n/locale.js';
|
38
|
+
*
|
37
39
|
* const translation = new Translations(parseLocale('en-GB'));
|
38
40
|
*
|
39
41
|
* translation.assignTranslations({
|
40
|
-
*
|
41
|
-
*
|
42
|
-
*
|
42
|
+
* text1: "click",
|
43
|
+
* text2: {
|
44
|
+
* 'one': 'click once',
|
45
|
+
* 'other': 'click n times'
|
46
|
+
* }
|
47
|
+
* });
|
48
|
+
*
|
49
|
+
* console.log(translation.getText('text1'));
|
50
|
+
* // ↦ click
|
43
51
|
*
|
44
|
-
* translation.
|
45
|
-
*
|
52
|
+
* console.log(translation.getPluralRuleText('text2',1));
|
53
|
+
* // -> click once
|
54
|
+
* console.log(translation.getPluralRuleText('text2',2));
|
55
|
+
* // -> click n times
|
46
56
|
*
|
47
57
|
* @since 1.13.0
|
48
58
|
* @copyright schukai GmbH
|
@@ -205,6 +215,5 @@ class Translations extends Base {
|
|
205
215
|
|
206
216
|
}
|
207
217
|
|
208
|
-
|
209
218
|
assignToNamespace('Monster.I18n', Translations);
|
210
219
|
export {Monster, Translations}
|
@@ -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.26.0/dist/monster.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.26.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.26.0/dist/monster.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.26.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.26.0/dist/monster.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.26.0/dist/modules/logging/logentry.js';
|
27
27
|
* console.log(new LogEntry())
|
28
28
|
* </script>
|
29
29
|
* ```
|
package/source/logging/logger.js
CHANGED
@@ -65,7 +65,7 @@ const OFF = 0;
|
|
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.26.0/dist/monster.js';
|
69
69
|
* new Monster.Logging.Logger()
|
70
70
|
* </script>
|
71
71
|
* ```
|
@@ -74,7 +74,7 @@ const OFF = 0;
|
|
74
74
|
*
|
75
75
|
* ```
|
76
76
|
* <script type="module">
|
77
|
-
* import {ID} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
77
|
+
* import {ID} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/logging/logger.js';
|
78
78
|
* new Logger()
|
79
79
|
* </script>
|
80
80
|
* ```
|
package/source/math/random.js
CHANGED
@@ -15,7 +15,7 @@ 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.
|
18
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
19
19
|
* Monster.Math.random(1,10)
|
20
20
|
* // ↦ 5
|
21
21
|
* </script>
|
@@ -25,7 +25,7 @@ import {getGlobal} from '../types/global.js';
|
|
25
25
|
*
|
26
26
|
* ```
|
27
27
|
* <script type="module">
|
28
|
-
* import {random} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
28
|
+
* import {random} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/math/random.js';
|
29
29
|
* random(1,10)
|
30
30
|
* // ↦ 5
|
31
31
|
* </script>
|
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.26.0/dist/monster.js';
|
69
69
|
* function hello() {
|
70
70
|
* console.log('Hello World!');
|
71
71
|
* }
|