@schukai/monster 1.17.1 → 1.20.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG +32 -0
- 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 +1 -1
- 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 +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 +2 -2
- package/dist/modules/dom/events.js +2 -2
- package/dist/modules/dom/locale.js +1 -1
- package/dist/modules/dom/namespace.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 +1 -1
- package/dist/modules/dom/util.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 +2 -0
- package/dist/modules/types/dataurl.js +2 -0
- 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 +2 -0
- package/dist/modules/types/namespace.js +1 -1
- 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/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/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/monster.dev.js +1018 -341
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +2 -2
- package/package.json +6 -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 +6 -6
- package/source/data/diff.js +4 -4
- 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 +3 -2
- package/source/dom/attributes.js +27 -27
- package/source/dom/customcontrol.js +22 -13
- package/source/dom/customelement.js +126 -6
- package/source/dom/events.js +21 -9
- package/source/dom/locale.js +3 -2
- package/source/dom/template.js +18 -6
- package/source/dom/theme.js +4 -3
- package/source/dom/updater.js +9 -6
- package/source/dom/util.js +6 -6
- package/source/i18n/locale.js +4 -4
- package/source/i18n/provider.js +3 -3
- package/source/i18n/providers/fetch.js +5 -5
- package/source/i18n/translations.js +2 -2
- 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 +2 -2
- package/source/types/base.js +2 -2
- package/source/types/basewithoptions.js +2 -2
- package/source/types/binary.js +92 -0
- package/source/types/dataurl.js +176 -0
- package/source/types/global.js +4 -4
- package/source/types/id.js +2 -2
- package/source/types/is.js +21 -21
- package/source/types/mediatype.js +236 -0
- package/source/types/observer.js +3 -3
- package/source/types/observerlist.js +2 -2
- package/source/types/package.d.ts +1 -0
- package/source/types/proxyobserver.js +5 -5
- package/source/types/queue.js +4 -3
- package/source/types/randomid.js +3 -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 +3 -2
- package/source/types/validate.js +20 -20
- package/source/types/version.js +7 -6
- package/source/util/clone.js +2 -2
- package/source/util/comparator.js +3 -3
- package/source/util/freeze.js +2 -2
- package/test/cases/data/diff.js +29 -2
- package/test/cases/dom/customelement.js +85 -12
- package/test/cases/dom/events.js +5 -3
- package/test/cases/monster.js +1 -1
- package/test/cases/types/binary.js +27 -0
- package/test/cases/types/dataurl.js +58 -0
- package/test/cases/types/mediatype.js +60 -0
- package/test/web/import.js +3 -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 +3 -3
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.20.0/dist/modules/i18n/provider.js';
|
19
19
|
* console.log(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.20.0/dist/modules/i18n/provider.js';
|
28
28
|
* console.log(new Provider())
|
29
29
|
* </script>
|
30
30
|
* ```
|
@@ -32,7 +32,7 @@ import {Translations} from "./translations.js"
|
|
32
32
|
* @since 1.13.0
|
33
33
|
* @copyright schukai GmbH
|
34
34
|
* @memberOf Monster.I18n
|
35
|
-
* @see https://datatracker.ietf.org/doc/html/rfc3066
|
35
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc3066}
|
36
36
|
*/
|
37
37
|
class Provider extends BaseWithOptions {
|
38
38
|
|
@@ -27,7 +27,7 @@ const optionsSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
27
27
|
*
|
28
28
|
* ```
|
29
29
|
* <script type="module">
|
30
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
30
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/i18n/providers/fetch.js';
|
31
31
|
* console.log(new Monster.I18n.Providers.Fetch())
|
32
32
|
* </script>
|
33
33
|
* ```
|
@@ -36,7 +36,7 @@ const optionsSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
36
36
|
*
|
37
37
|
* ```
|
38
38
|
* <script type="module">
|
39
|
-
* import {Fetch} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
39
|
+
* import {Fetch} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/i18n/providers/fetch.js';
|
40
40
|
* console.log(new Fetch())
|
41
41
|
* </script>
|
42
42
|
* ```
|
@@ -44,7 +44,7 @@ const optionsSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
44
44
|
* @since 1.13.0
|
45
45
|
* @copyright schukai GmbH
|
46
46
|
* @memberOf Monster.I18n.Providers
|
47
|
-
* @see https://datatracker.ietf.org/doc/html/rfc3066
|
47
|
+
* @see {@link https://datatracker.ietf.org/doc/html/rfc3066}
|
48
48
|
*/
|
49
49
|
class Fetch extends Provider {
|
50
50
|
|
@@ -53,7 +53,7 @@ class Fetch extends Provider {
|
|
53
53
|
*
|
54
54
|
* @param {string|URL} url
|
55
55
|
* @param {Object} options see {@link Monster.I18n.Providers.Fetch#defaults}
|
56
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/fetch
|
56
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}
|
57
57
|
*/
|
58
58
|
constructor(url, options) {
|
59
59
|
super(options);
|
@@ -92,7 +92,7 @@ class Fetch extends Provider {
|
|
92
92
|
* @property {String} fetch.redirect=follow
|
93
93
|
* @property {String} fetch.referrerPolicy=no-referrer
|
94
94
|
*
|
95
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
|
95
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API}
|
96
96
|
*/
|
97
97
|
get defaults() {
|
98
98
|
|
@@ -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.20.0/dist/modules/i18n/translations.js';
|
21
21
|
* console.log(new Monster.I18n.Translations())
|
22
22
|
* </script>
|
23
23
|
* ```
|
@@ -26,7 +26,7 @@ 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.20.0/dist/modules/i18n/translations.js';
|
30
30
|
* console.log(new Translations())
|
31
31
|
* </script>
|
32
32
|
* ```
|
@@ -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.20.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.20.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.20.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.20.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.20.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.20.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.20.0/dist/modules/logging/logger.js';
|
69
69
|
* console.log(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.20.0/dist/modules/logging/logger.js';
|
78
78
|
* console.log(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.20.0/dist/modules/math/random.js';
|
19
19
|
* console.log(Monster.Math.random(1,10)) // ↦ 5
|
20
20
|
* </script>
|
21
21
|
* ```
|
@@ -24,7 +24,7 @@ import {getGlobal} from '../types/global.js';
|
|
24
24
|
*
|
25
25
|
* ```
|
26
26
|
* <script type="module">
|
27
|
-
* import {random} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
27
|
+
* import {random} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/math/random.js';
|
28
28
|
* console.log(random(1,10)) // ↦ 5
|
29
29
|
* </script>
|
30
30
|
* ```
|
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.20.0/dist/modules/namespace.js';
|
69
69
|
* function hello() {
|
70
70
|
* console.log('Hello World!');
|
71
71
|
* }
|
package/source/text/formatter.js
CHANGED
@@ -18,7 +18,7 @@ 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.
|
21
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/text/formatter.js';
|
22
22
|
* console.log(new Monster.Text.Formatter())
|
23
23
|
* </script>
|
24
24
|
* ```
|
@@ -27,7 +27,7 @@ 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.
|
30
|
+
* import {Formatter} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/text/formatter.js';
|
31
31
|
* console.log(new Formatter())
|
32
32
|
* </script>
|
33
33
|
* ```
|
package/source/types/base.js
CHANGED
@@ -13,7 +13,7 @@ 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.
|
16
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/base.js';
|
17
17
|
* console.log(new Monster.Types.Base())
|
18
18
|
* </script>
|
19
19
|
* ```
|
@@ -22,7 +22,7 @@ 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.
|
25
|
+
* import {Base} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/base.js';
|
26
26
|
* console.log(new Base())
|
27
27
|
* </script>
|
28
28
|
* ```
|
@@ -23,7 +23,7 @@ const optionsSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
23
23
|
*
|
24
24
|
* ```
|
25
25
|
* <script type="module">
|
26
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
26
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/basewithoptions.js';
|
27
27
|
* console.log(new Monster.Types.BaseWithOptions())
|
28
28
|
* </script>
|
29
29
|
* ```
|
@@ -32,7 +32,7 @@ const optionsSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
32
32
|
*
|
33
33
|
* ```
|
34
34
|
* <script type="module">
|
35
|
-
* import {BaseWithOptions} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
35
|
+
* import {BaseWithOptions} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/basewithoptions.js';
|
36
36
|
* console.log(new BaseWithOptions())
|
37
37
|
* </script>
|
38
38
|
* ```
|
@@ -0,0 +1,92 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
import {assignToNamespace} from "../namespace.js";
|
4
|
+
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @author schukai GmbH
|
8
|
+
*/
|
9
|
+
import {Monster, validateString} from "./validate.js";
|
10
|
+
|
11
|
+
/**
|
12
|
+
* You can call the function via the monster namespace `Monster.Types.toBinary()`.
|
13
|
+
*
|
14
|
+
* ```
|
15
|
+
* <script type="module">
|
16
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/binary.js';
|
17
|
+
* console.log(Monster.Types.toBinary())
|
18
|
+
* </script>
|
19
|
+
* ```
|
20
|
+
*
|
21
|
+
* Alternatively, you can also integrate this function individually.
|
22
|
+
*
|
23
|
+
* ```
|
24
|
+
* <script type="module">
|
25
|
+
* import {toBinary} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/binary.js';
|
26
|
+
* console.log(toBinary())
|
27
|
+
* </script>
|
28
|
+
* ```
|
29
|
+
*
|
30
|
+
* @param {String} binary
|
31
|
+
* @return {String}
|
32
|
+
* @throws {TypeError} value is not a string
|
33
|
+
* @memberOf Monster.Types
|
34
|
+
* @since 1.18.0
|
35
|
+
*/
|
36
|
+
function toBinary(string) {
|
37
|
+
const codeUnits = new Uint16Array(validateString(string).length);
|
38
|
+
for (let i = 0; i < codeUnits.length; i++) {
|
39
|
+
codeUnits[i] = string.charCodeAt(i);
|
40
|
+
}
|
41
|
+
|
42
|
+
const charCodes = new Uint8Array(codeUnits.buffer);
|
43
|
+
let result = '';
|
44
|
+
|
45
|
+
for (let i = 0; i < charCodes.byteLength; i++) {
|
46
|
+
result += String.fromCharCode(charCodes[i]);
|
47
|
+
}
|
48
|
+
|
49
|
+
return result;
|
50
|
+
}
|
51
|
+
|
52
|
+
/**
|
53
|
+
* You can call the function via the monster namespace `Monster.Types.fromBinary()`.
|
54
|
+
*
|
55
|
+
* ```
|
56
|
+
* <script type="module">
|
57
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/binary.js';
|
58
|
+
* console.log(Monster.Types.fromBinary())
|
59
|
+
* </script>
|
60
|
+
* ```
|
61
|
+
*
|
62
|
+
* Alternatively, you can also integrate this function individually.
|
63
|
+
*
|
64
|
+
* ```
|
65
|
+
* <script type="module">
|
66
|
+
* import {fromBinary} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/binary.js';
|
67
|
+
* console.log(fromBinary())
|
68
|
+
* </script>
|
69
|
+
* ```
|
70
|
+
*
|
71
|
+
* @param {String} binary
|
72
|
+
* @return {String}
|
73
|
+
* @throws {TypeError} value is not a string
|
74
|
+
* @memberOf Monster.Types
|
75
|
+
* @since 1.18.0
|
76
|
+
*/
|
77
|
+
function fromBinary(binary) {
|
78
|
+
const bytes = new Uint8Array(validateString(binary).length);
|
79
|
+
for (let i = 0; i < bytes.length; i++) {
|
80
|
+
bytes[i] = binary.charCodeAt(i);
|
81
|
+
}
|
82
|
+
const charCodes = new Uint16Array(bytes.buffer);
|
83
|
+
let result = '';
|
84
|
+
for (let i = 0; i < charCodes.length; i++) {
|
85
|
+
result += String.fromCharCode(charCodes[i]);
|
86
|
+
}
|
87
|
+
return result;
|
88
|
+
}
|
89
|
+
|
90
|
+
|
91
|
+
assignToNamespace('Monster.Types', toBinary, fromBinary);
|
92
|
+
export {Monster, toBinary, fromBinary};
|
@@ -0,0 +1,176 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
import {assignToNamespace} from "../namespace.js";
|
4
|
+
/**
|
5
|
+
* @author schukai GmbH
|
6
|
+
*/
|
7
|
+
import {Base, Monster} from "./base.js";
|
8
|
+
import {isString} from "./is.js";
|
9
|
+
import {MediaType, parseMediaType} from "./mediatype.js";
|
10
|
+
import {validateBoolean, validateInstance, validateString} from "./validate.js";
|
11
|
+
|
12
|
+
/**
|
13
|
+
* @private
|
14
|
+
* @type {symbol}
|
15
|
+
*/
|
16
|
+
const internal = Symbol('internal');
|
17
|
+
|
18
|
+
/**
|
19
|
+
* You can create an object via the monster namespace `new Monster.Types.DataUrl()`.
|
20
|
+
*
|
21
|
+
* ```
|
22
|
+
* <script type="module">
|
23
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/dataurl.js';
|
24
|
+
* console.log(new Monster.Types.DataUrl())
|
25
|
+
* </script>
|
26
|
+
* ```
|
27
|
+
*
|
28
|
+
* Alternatively, you can also integrate this function individually.
|
29
|
+
*
|
30
|
+
* ```
|
31
|
+
* <script type="module">
|
32
|
+
* import {DataUrl} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/dataurl.js';
|
33
|
+
* console.log(new DataUrl())
|
34
|
+
* </script>
|
35
|
+
* ```
|
36
|
+
*
|
37
|
+
* @since 1.8.0
|
38
|
+
* @copyright schukai GmbH
|
39
|
+
* @memberOf Monster.Types
|
40
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
|
41
|
+
* @see https://datatracker.ietf.org/doc/html/rfc2397
|
42
|
+
*/
|
43
|
+
class DataUrl extends Base {
|
44
|
+
|
45
|
+
/**
|
46
|
+
*
|
47
|
+
* @param {String} content
|
48
|
+
* @param {String|Monster.Types.MediaType} mediatype
|
49
|
+
* @param {boolean} base64=true
|
50
|
+
*/
|
51
|
+
constructor(content, mediatype, base64) {
|
52
|
+
super();
|
53
|
+
|
54
|
+
if (isString(mediatype)) {
|
55
|
+
mediatype = parseMediaType(mediatype);
|
56
|
+
}
|
57
|
+
|
58
|
+
this[internal] = {
|
59
|
+
content: validateString(content),
|
60
|
+
mediatype: validateInstance(mediatype, MediaType),
|
61
|
+
base64: validateBoolean(base64 === undefined ? true : base64)
|
62
|
+
}
|
63
|
+
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
get content() {
|
68
|
+
return this[internal].base64 ? atob(this[internal].content) : this[internal].content;
|
69
|
+
}
|
70
|
+
|
71
|
+
get mediatype() {
|
72
|
+
return this[internal].mediatype;
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
/**
|
77
|
+
*
|
78
|
+
* @return {string}
|
79
|
+
* @see https://datatracker.ietf.org/doc/html/rfc2397
|
80
|
+
*/
|
81
|
+
toString() {
|
82
|
+
|
83
|
+
let content = this[internal].content;
|
84
|
+
|
85
|
+
if (this[internal].base64 === true) {
|
86
|
+
content = ';base64,' + content;
|
87
|
+
} else {
|
88
|
+
content = ',' + encodeURIComponent(content);
|
89
|
+
}
|
90
|
+
|
91
|
+
return 'data:' + this[internal].mediatype.toString() + content;
|
92
|
+
}
|
93
|
+
|
94
|
+
}
|
95
|
+
|
96
|
+
/**
|
97
|
+
* You can call the function via the monster namespace `Monster.Types.parseDataURL()`.
|
98
|
+
*
|
99
|
+
* ```
|
100
|
+
* <script type="module">
|
101
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/dataurl.js';
|
102
|
+
* console.log(Monster.Types.parseDataURL())
|
103
|
+
* </script>
|
104
|
+
* ```
|
105
|
+
*
|
106
|
+
* Alternatively, you can also integrate this function individually.
|
107
|
+
*
|
108
|
+
* ```
|
109
|
+
* <script type="module">
|
110
|
+
* import {parseDataURL} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/dataurl.js';
|
111
|
+
* console.log(parseDataURL())
|
112
|
+
* </script>
|
113
|
+
* ```
|
114
|
+
*
|
115
|
+
* Specification:
|
116
|
+
*
|
117
|
+
* ```
|
118
|
+
* dataurl := "data:" [ mediatype ] [ ";base64" ] "," data
|
119
|
+
* mediatype := [ type "/" subtype ] *( ";" parameter )
|
120
|
+
* data := *urlchar
|
121
|
+
* parameter := attribute "=" value
|
122
|
+
* ```
|
123
|
+
*
|
124
|
+
* @param {String} dataurl
|
125
|
+
* @return {Monster.Types.DataUrl}
|
126
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
|
127
|
+
* @see https://datatracker.ietf.org/doc/html/rfc2397
|
128
|
+
* @throws {TypeError} incorrect or missing data protocol
|
129
|
+
* @throws {TypeError} malformed data url
|
130
|
+
* @memberOf Monster.Types
|
131
|
+
*/
|
132
|
+
function parseDataURL(dataurl) {
|
133
|
+
|
134
|
+
validateString(dataurl);
|
135
|
+
|
136
|
+
dataurl = dataurl.trim();
|
137
|
+
|
138
|
+
if (dataurl.substring(0, 5) !== 'data:') {
|
139
|
+
throw new TypeError('incorrect or missing data protocol')
|
140
|
+
}
|
141
|
+
|
142
|
+
dataurl = dataurl.substring(5);
|
143
|
+
|
144
|
+
let p = dataurl.indexOf(',');
|
145
|
+
if (p === -1) {
|
146
|
+
throw new TypeError('malformed data url')
|
147
|
+
}
|
148
|
+
|
149
|
+
let content = dataurl.substring(p + 1);
|
150
|
+
let mediatypeAndBase64 = dataurl.substring(0, p).trim();
|
151
|
+
let mediatype = 'text/plain;charset=US-ASCII';
|
152
|
+
let base64Flag = false;
|
153
|
+
|
154
|
+
if (mediatypeAndBase64 !== "") {
|
155
|
+
mediatype = mediatypeAndBase64;
|
156
|
+
if (mediatypeAndBase64.endsWith('base64')) {
|
157
|
+
let i = mediatypeAndBase64.lastIndexOf(';');
|
158
|
+
mediatype = mediatypeAndBase64.substring(0, i);
|
159
|
+
base64Flag = true;
|
160
|
+
} else {
|
161
|
+
content = decodeURIComponent(content);
|
162
|
+
}
|
163
|
+
|
164
|
+
mediatype = parseMediaType(mediatype);
|
165
|
+
} else {
|
166
|
+
content = decodeURIComponent(content);
|
167
|
+
}
|
168
|
+
|
169
|
+
return new DataUrl(content, mediatype, base64Flag);
|
170
|
+
|
171
|
+
|
172
|
+
}
|
173
|
+
|
174
|
+
|
175
|
+
assignToNamespace('Monster.Types', parseDataURL, DataUrl);
|
176
|
+
export {Monster, parseDataURL, DataUrl};
|
package/source/types/global.js
CHANGED
@@ -78,7 +78,7 @@ function getGlobal() {
|
|
78
78
|
*
|
79
79
|
* ```
|
80
80
|
* <script type="module">
|
81
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
81
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/global.js';
|
82
82
|
* console.log(Monster.Types.getGlobalObject('document')) // ↦ { }
|
83
83
|
* </script>
|
84
84
|
* ```
|
@@ -87,7 +87,7 @@ function getGlobal() {
|
|
87
87
|
*
|
88
88
|
* ```
|
89
89
|
* <script type="module">
|
90
|
-
* import {getGlobalObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
90
|
+
* import {getGlobalObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/global.js';
|
91
91
|
* console.log(getGlobalObject('document')) // ↦ { }
|
92
92
|
* </script>
|
93
93
|
* ```
|
@@ -115,7 +115,7 @@ function getGlobalObject(name) {
|
|
115
115
|
*
|
116
116
|
* ```
|
117
117
|
* <script type="module">
|
118
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
118
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/global.js';
|
119
119
|
* console.log(Monster.Types.getGlobalFunction('parseInt')) // ↦ f parseInt() { }
|
120
120
|
* </script>
|
121
121
|
* ```
|
@@ -124,7 +124,7 @@ function getGlobalObject(name) {
|
|
124
124
|
*
|
125
125
|
* ```
|
126
126
|
* <script type="module">
|
127
|
-
* import {getGlobalFunction} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
127
|
+
* import {getGlobalFunction} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.20.0/dist/modules/types/global.js';
|
128
128
|
* console.log(getGlobalFunction('parseInt')) // ↦ f parseInt() { }
|
129
129
|
* </script>
|
130
130
|
* ```
|
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.20.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.20.0/dist/modules/types/id.js';
|
37
37
|
* console.log(new ID())
|
38
38
|
* </script>
|
39
39
|
* ```
|