@schukai/monster 3.51.5 → 3.52.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +17 -0
- package/README.md +15 -12
- package/example/components/form/button.mjs +10 -0
- package/example/components/form/select.mjs +25 -0
- package/example/components/form/tree-select.mjs +27 -0
- package/example/components/host/host.mjs +0 -0
- package/example/components/notify/message.mjs +4 -0
- package/example/components/notify/notify.mjs +4 -0
- package/example/components/state/log.mjs +0 -0
- package/example/components/state/state.mjs +0 -0
- package/package.json +6 -2
- package/source/components/constants.mjs +132 -0
- package/source/components/datatable/columnbar.mjs +310 -0
- package/source/components/datatable/constants.mjs +121 -0
- package/source/components/datatable/dataset.mjs +219 -0
- package/source/components/datatable/datasource/dom.mjs +186 -0
- package/source/components/datatable/datasource/namespace.mjs +13 -0
- package/source/components/datatable/datasource/rest.mjs +400 -0
- package/source/components/datatable/datasource.mjs +102 -0
- package/source/components/datatable/datatable/header.mjs +268 -0
- package/source/components/datatable/datatable/namespace.mjs +13 -0
- package/source/components/datatable/datatable.mjs +789 -0
- package/source/components/datatable/embedded-pagination.mjs +113 -0
- package/source/components/datatable/filter/abstract-base.mjs +31 -0
- package/source/components/datatable/filter/date-range.mjs +1041 -0
- package/source/components/datatable/filter/input.mjs +175 -0
- package/source/components/datatable/filter/namespace.mjs +13 -0
- package/source/components/datatable/filter/range.mjs +671 -0
- package/source/components/datatable/filter/select.mjs +65 -0
- package/source/components/datatable/filter/settings.mjs +116 -0
- package/source/components/datatable/filter-button.mjs +98 -0
- package/source/components/datatable/filter.mjs +929 -0
- package/source/components/datatable/namespace.mjs +11 -0
- package/source/components/datatable/pagination.mjs +456 -0
- package/source/components/datatable/style/column-bar.pcss +123 -0
- package/source/components/datatable/style/dataset.pcss +13 -0
- package/source/components/datatable/style/datasource.pcss +16 -0
- package/source/components/datatable/style/datatable.pcss +239 -0
- package/source/components/datatable/style/embedded-pagination.pcss +101 -0
- package/source/components/datatable/style/filter-button.pcss +22 -0
- package/source/components/datatable/style/filter-controls-defaults.pcss +46 -0
- package/source/components/datatable/style/filter-date-range.pcss +9 -0
- package/source/components/datatable/style/filter-range.pcss +5 -0
- package/source/components/datatable/style/filter.pcss +156 -0
- package/source/components/datatable/style/pagination.pcss +59 -0
- package/source/components/datatable/style/select-filter.pcss +27 -0
- package/source/components/datatable/stylesheet/column-bar.mjs +33 -0
- package/source/components/datatable/stylesheet/dataset.mjs +33 -0
- package/source/components/datatable/stylesheet/datasource.mjs +33 -0
- package/source/components/datatable/stylesheet/datatable.mjs +33 -0
- package/source/components/datatable/stylesheet/embedded-pagination.mjs +33 -0
- package/source/components/datatable/stylesheet/filter-button.mjs +33 -0
- package/source/components/datatable/stylesheet/filter-controls-defaults.mjs +33 -0
- package/source/components/datatable/stylesheet/filter-date-range.mjs +33 -0
- package/source/components/datatable/stylesheet/filter-range.mjs +33 -0
- package/source/components/datatable/stylesheet/filter.mjs +33 -0
- package/source/components/datatable/stylesheet/namespace.mjs +13 -0
- package/source/components/datatable/stylesheet/pagination.mjs +33 -0
- package/source/components/datatable/stylesheet/select-filter.mjs +33 -0
- package/source/components/datatable/util.mjs +60 -0
- package/source/components/form/action-button.mjs +262 -0
- package/source/components/form/api-button.mjs +515 -0
- package/source/components/form/button-bar.mjs +739 -0
- package/source/components/form/button.mjs +350 -0
- package/source/components/form/confirm-button.mjs +330 -0
- package/source/components/form/constants.mjs +111 -0
- package/source/components/form/context-help.mjs +123 -0
- package/source/components/form/events.mjs +84 -0
- package/source/components/form/form.mjs +601 -0
- package/source/components/form/message-state-button.mjs +396 -0
- package/source/components/form/namespace.mjs +13 -0
- package/source/components/form/popper-button.mjs +435 -0
- package/source/components/form/popper.mjs +487 -0
- package/source/components/form/reload.mjs +360 -0
- package/source/components/form/select.mjs +2314 -0
- package/source/components/form/shadow-reload.mjs +137 -0
- package/source/components/form/state-button.mjs +182 -0
- package/source/components/form/style/action-button.pcss +41 -0
- package/source/components/form/style/api-button.pcss +0 -0
- package/source/components/form/style/button-bar.pcss +51 -0
- package/source/components/form/style/button.pcss +8 -0
- package/source/components/form/style/confirm-button.pcss +17 -0
- package/source/components/form/style/context-help.pcss +16 -0
- package/source/components/form/style/form.pcss +10 -0
- package/source/components/form/style/message-state-button.pcss +10 -0
- package/source/components/form/style/popper-button.pcss +16 -0
- package/source/components/form/style/popper.pcss +8 -0
- package/source/components/form/style/select.pcss +265 -0
- package/source/components/form/style/state-button.pcss +116 -0
- package/source/components/form/style/tabs.pcss +170 -0
- package/source/components/form/style/tree-select.pcss +81 -0
- package/source/components/form/stylesheet/action-button.mjs +33 -0
- package/source/components/form/stylesheet/api-button.mjs +33 -0
- package/source/components/form/stylesheet/button-bar.mjs +33 -0
- package/source/components/form/stylesheet/button.mjs +33 -0
- package/source/components/form/stylesheet/confirm-button.mjs +33 -0
- package/source/components/form/stylesheet/context-help.mjs +33 -0
- package/source/components/form/stylesheet/form.mjs +33 -0
- package/source/components/form/stylesheet/message-state-button.mjs +33 -0
- package/source/components/form/stylesheet/namespace.mjs +13 -0
- package/source/components/form/stylesheet/popper-button.mjs +33 -0
- package/source/components/form/stylesheet/popper.mjs +33 -0
- package/source/components/form/stylesheet/select.mjs +33 -0
- package/source/components/form/stylesheet/state-button.mjs +33 -0
- package/source/components/form/stylesheet/tabs.mjs +33 -0
- package/source/components/form/stylesheet/tree-select.mjs +33 -0
- package/source/components/form/tabs.mjs +1011 -0
- package/source/components/form/template.mjs +373 -0
- package/source/components/form/tree-select.mjs +527 -0
- package/source/components/form/types/namespace.mjs +13 -0
- package/source/components/form/types/state.mjs +93 -0
- package/source/components/form/util/fetch.mjs +133 -0
- package/source/components/form/util/floating-ui.mjs +245 -0
- package/source/components/form/util/namespace.mjs +13 -0
- package/source/components/form/util/popper.mjs +49 -0
- package/source/components/host/call-button.mjs +236 -0
- package/source/components/host/collapse.mjs +526 -0
- package/source/components/host/config-manager.mjs +304 -0
- package/source/components/host/constants.mjs +18 -0
- package/source/components/host/details.mjs +268 -0
- package/source/components/host/events.mjs +131 -0
- package/source/components/host/host.mjs +420 -0
- package/source/components/host/namespace.mjs +13 -0
- package/source/components/host/overlay.mjs +339 -0
- package/source/components/host/style/call-button.pcss +36 -0
- package/source/components/host/style/collapse.pcss +67 -0
- package/source/components/host/style/config-manager.pcss +5 -0
- package/source/components/host/style/details.pcss +68 -0
- package/source/components/host/style/host.pcss +43 -0
- package/source/components/host/style/overlay.pcss +73 -0
- package/source/components/host/style/toggle-button.pcss +36 -0
- package/source/components/host/style/viewer.pcss +13 -0
- package/source/components/host/stylesheet/call-button.mjs +33 -0
- package/source/components/host/stylesheet/collapse.mjs +33 -0
- package/source/components/host/stylesheet/config-manager.mjs +33 -0
- package/source/components/host/stylesheet/details.mjs +33 -0
- package/source/components/host/stylesheet/host.mjs +33 -0
- package/source/components/host/stylesheet/namespace.mjs +13 -0
- package/source/components/host/stylesheet/overlay.mjs +33 -0
- package/source/components/host/stylesheet/toggle-button.mjs +33 -0
- package/source/components/host/stylesheet/viewer.mjs +33 -0
- package/source/components/host/toggle-button.mjs +88 -0
- package/source/components/host/util.mjs +23 -0
- package/source/components/host/viewer.mjs +309 -0
- package/source/components/namespace.mjs +14 -0
- package/source/components/notify/constants.mjs +15 -0
- package/source/components/notify/events.mjs +15 -0
- package/source/components/notify/message.mjs +374 -0
- package/source/components/notify/namespace.mjs +15 -0
- package/source/components/notify/notify.mjs +236 -0
- package/source/components/notify/style/message.pcss +57 -0
- package/source/components/notify/style/notify.pcss +118 -0
- package/source/components/notify/stylesheet/message.mjs +33 -0
- package/source/components/notify/stylesheet/namespace.mjs +15 -0
- package/source/components/notify/stylesheet/notify.mjs +33 -0
- package/source/components/state/log/entry.mjs +126 -0
- package/source/components/state/log/namespace.mjs +13 -0
- package/source/components/state/log.mjs +275 -0
- package/source/components/state/namespace.mjs +13 -0
- package/source/components/state/state.mjs +131 -0
- package/source/components/state/style/log.pcss +111 -0
- package/source/components/state/style/state.pcss +113 -0
- package/source/components/state/stylesheet/log.mjs +33 -0
- package/source/components/state/stylesheet/state.mjs +33 -0
- package/source/components/style/badge.pcss +92 -0
- package/source/components/style/border.pcss +77 -0
- package/source/components/style/button.pcss +105 -0
- package/source/components/style/card.pcss +108 -0
- package/source/components/style/color.pcss +257 -0
- package/source/components/style/common.pcss +103 -0
- package/source/components/style/control.pcss +11 -0
- package/source/components/style/data-grid.pcss +43 -0
- package/source/components/style/display.pcss +42 -0
- package/source/components/style/floating-ui.pcss +33 -0
- package/source/components/style/form.pcss +5 -0
- package/source/components/style/host.pcss +15 -0
- package/source/components/style/link.pcss +63 -0
- package/source/components/style/mixin/badge.pcss +18 -0
- package/source/components/style/mixin/button.pcss +54 -0
- package/source/components/style/mixin/form.pcss +247 -0
- package/source/components/style/mixin/hover.pcss +8 -0
- package/source/components/style/mixin/media.pcss +107 -0
- package/source/components/style/mixin/property.pcss +288 -0
- package/source/components/style/mixin/skeleton.pcss +26 -0
- package/source/components/style/mixin/spinner.pcss +24 -0
- package/source/components/style/mixin/typography.pcss +52 -0
- package/source/components/style/normalize.pcss +14 -0
- package/source/components/style/popper.pcss +78 -0
- package/source/components/style/property.pcss +17 -0
- package/source/components/style/ripple.pcss +14 -0
- package/source/components/style/skeleton.pcss +28 -0
- package/source/components/style/space.pcss +47 -0
- package/source/components/style/spinner.pcss +6 -0
- package/source/components/style/table.pcss +46 -0
- package/source/components/style/theme.pcss +119 -0
- package/source/components/style/typography.pcss +131 -0
- package/source/components/stylesheet/badge.mjs +33 -0
- package/source/components/stylesheet/border.mjs +33 -0
- package/source/components/stylesheet/button.mjs +33 -0
- package/source/components/stylesheet/card.mjs +33 -0
- package/source/components/stylesheet/color.mjs +33 -0
- package/source/components/stylesheet/common.mjs +33 -0
- package/source/components/stylesheet/control.mjs +33 -0
- package/source/components/stylesheet/data-grid.mjs +33 -0
- package/source/components/stylesheet/display.mjs +33 -0
- package/source/components/stylesheet/floating-ui.mjs +33 -0
- package/source/components/stylesheet/form.mjs +33 -0
- package/source/components/stylesheet/host.mjs +33 -0
- package/source/components/stylesheet/link.mjs +33 -0
- package/source/components/stylesheet/namespace.mjs +13 -0
- package/source/components/stylesheet/normalize.mjs +33 -0
- package/source/components/stylesheet/popper.mjs +33 -0
- package/source/components/stylesheet/property.mjs +33 -0
- package/source/components/stylesheet/ripple.mjs +33 -0
- package/source/components/stylesheet/skeleton.mjs +33 -0
- package/source/components/stylesheet/space.mjs +33 -0
- package/source/components/stylesheet/spinner.mjs +33 -0
- package/source/components/stylesheet/table.mjs +33 -0
- package/source/components/stylesheet/theme.mjs +33 -0
- package/source/components/stylesheet/tree-menu.mjs +33 -0
- package/source/components/stylesheet/typography.mjs +33 -0
- package/source/components/tree-menu/namespace.mjs +13 -0
- package/source/components/tree-menu/style/tree-menu.pcss +107 -0
- package/source/components/tree-menu/stylesheet/namespace.mjs +13 -0
- package/source/components/tree-menu/stylesheet/tree-menu.mjs +33 -0
- package/source/components/tree-menu/tree-menu.mjs +660 -0
- package/source/constraints/abstract.mjs +17 -24
- package/source/constraints/abstractoperator.mjs +27 -22
- package/source/constraints/andoperator.mjs +20 -17
- package/source/constraints/invalid.mjs +17 -17
- package/source/constraints/isarray.mjs +20 -20
- package/source/constraints/isobject.mjs +20 -20
- package/source/constraints/oroperator.mjs +45 -45
- package/source/constraints/valid.mjs +17 -17
- package/source/data/buildmap.mjs +108 -103
- package/source/data/buildtree.mjs +59 -57
- package/source/data/datasource/dom.mjs +80 -84
- package/source/data/datasource/namespace.mjs +1 -1
- package/source/data/datasource/server/restapi/data-fetch-error.mjs +27 -25
- package/source/data/datasource/server/restapi/writeerror.mjs +34 -32
- package/source/data/datasource/server/restapi.mjs +176 -177
- package/source/data/datasource/server/webconnect.mjs +150 -156
- package/source/data/datasource/server.mjs +58 -59
- package/source/data/datasource/storage/localstorage.mjs +25 -24
- package/source/data/datasource/storage/sessionstorage.mjs +28 -25
- package/source/data/datasource/storage.mjs +74 -73
- package/source/data/datasource.mjs +176 -167
- package/source/data/diff.mjs +98 -97
- package/source/data/extend.mjs +42 -42
- package/source/data/pathfinder.mjs +301 -288
- package/source/data/pipe.mjs +36 -36
- package/source/data/transformer.mjs +742 -726
- package/source/dom/assembler.mjs +44 -44
- package/source/dom/attributes.mjs +142 -122
- package/source/dom/constants.mjs +62 -58
- package/source/dom/customcontrol.mjs +299 -299
- package/source/dom/customelement.mjs +843 -806
- package/source/dom/dimension.mjs +56 -46
- package/source/dom/events.mjs +74 -69
- package/source/dom/focusmanager.mjs +175 -175
- package/source/dom/locale.mjs +28 -28
- package/source/dom/ready.mjs +13 -13
- package/source/dom/resource/data.mjs +117 -111
- package/source/dom/resource/link/stylesheet.mjs +16 -16
- package/source/dom/resource/link.mjs +94 -96
- package/source/dom/resource/script.mjs +72 -74
- package/source/dom/resource.mjs +174 -172
- package/source/dom/resourcemanager.mjs +152 -156
- package/source/dom/slotted.mjs +78 -80
- package/source/dom/template.mjs +126 -112
- package/source/dom/theme.mjs +35 -35
- package/source/dom/updater.mjs +673 -651
- package/source/dom/util/extract-keys.mjs +34 -22
- package/source/dom/util/init-options-from-attributes.mjs +46 -38
- package/source/dom/util/namespace.mjs +13 -0
- package/source/dom/util/set-option-from-attribute.mjs +35 -29
- package/source/dom/util.mjs +112 -81
- package/source/dom/worker/factory.mjs +83 -83
- package/source/i18n/formatter.mjs +75 -73
- package/source/i18n/locale.mjs +146 -144
- package/source/i18n/provider.mjs +70 -64
- package/source/i18n/providers/embed.mjs +136 -127
- package/source/i18n/providers/fetch.mjs +84 -76
- package/source/i18n/translations.mjs +205 -195
- package/source/logging/handler/console.mjs +36 -36
- package/source/logging/handler.mjs +140 -140
- package/source/logging/logentry.mjs +25 -25
- package/source/logging/logger.mjs +177 -175
- package/source/math/random.mjs +63 -59
- package/source/monster.mjs +223 -103
- package/source/net/webconnect/message.mjs +31 -31
- package/source/net/webconnect.mjs +278 -271
- package/source/text/bracketed-key-value-hash.mjs +182 -179
- package/source/text/formatter.mjs +235 -210
- package/source/text/generate-range-comparison-expression.mjs +56 -34
- package/source/text/namespace.mjs +1 -1
- package/source/types/base.mjs +69 -61
- package/source/types/basewithoptions.mjs +46 -46
- package/source/types/binary.mjs +20 -20
- package/source/types/dataurl.mjs +96 -90
- package/source/types/global.mjs +45 -39
- package/source/types/id.mjs +25 -25
- package/source/types/internal.mjs +115 -114
- package/source/types/is.mjs +56 -40
- package/source/types/mediatype.mjs +119 -119
- package/source/types/namespace.mjs +1 -1
- package/source/types/node.mjs +160 -150
- package/source/types/nodelist.mjs +94 -96
- package/source/types/noderecursiveiterator.mjs +50 -50
- package/source/types/observablequeue.mjs +73 -73
- package/source/types/observer.mjs +104 -104
- package/source/types/observerlist.mjs +66 -66
- package/source/types/proxyobserver.mjs +210 -210
- package/source/types/queue.mjs +63 -63
- package/source/types/randomid.mjs +13 -13
- package/source/types/regex.mjs +3 -1
- package/source/types/stack.mjs +64 -64
- package/source/types/tokenlist.mjs +206 -205
- package/source/types/typeof.mjs +12 -10
- package/source/types/uniquequeue.mjs +48 -48
- package/source/types/uuid.mjs +32 -32
- package/source/types/validate.mjs +67 -67
- package/source/types/version.mjs +115 -105
- package/source/util/clone.mjs +103 -91
- package/source/util/comparator.mjs +97 -97
- package/source/util/deadmansswitch.mjs +40 -44
- package/source/util/freeze.mjs +10 -9
- package/source/util/namespace.mjs +1 -1
- package/source/util/processing.mjs +104 -105
- package/source/util/runtime.mjs +56 -44
- package/source/util/trimspaces.mjs +24 -24
- package/test/cases/components/form/button.mjs +122 -0
- package/test/cases/components/form/confirm-button.mjs +127 -0
- package/test/cases/components/form/form.mjs +317 -0
- package/test/cases/components/form/reload.mjs +188 -0
- package/test/cases/components/form/select.mjs +229 -0
- package/test/cases/components/form/state-button.mjs +130 -0
- package/test/cases/components/form/tabs.mjs +98 -0
- package/test/cases/components/form/template.mjs +189 -0
- package/test/cases/components/form/tree-select.mjs +216 -0
- package/test/cases/components/host/details.mjs +68 -0
- package/test/cases/components/host/host.mjs +70 -0
- package/test/cases/components/host/overlay.mjs +60 -0
- package/test/cases/components/host/util.mjs +79 -0
- package/test/cases/components/notify/message.mjs +39 -0
- package/test/cases/components/notify/notify.mjs +89 -0
- package/test/cases/dom/customcontrol.mjs +5 -4
- package/test/cases/math/random.mjs +0 -1
- package/test/cases/monster.mjs +1 -1
- package/test/cases/net/webconnect/message.mjs +0 -1
- package/test/cases/types/node.mjs +1 -1
- package/test/util/chai-dom.mjs +2 -2
- package/test/util/intersection-mock.mjs +69 -0
- package/test/util/jsdom.mjs +41 -25
- package/test/util/localstorage.mjs +1 -0
- package/test/util/resize-observer.mjs +29 -0
- package/test/util/websocket.mjs +4 -1
- package/test/web/import.js +16 -1
- package/test/web/test.html +28 -5
- package/test/web/tests.js +30398 -17879
@@ -10,14 +10,17 @@ import { Base } from "../types/base.mjs";
|
|
10
10
|
import { getGlobal, getGlobalObject } from "../types/global.mjs";
|
11
11
|
import { ID } from "../types/id.mjs";
|
12
12
|
import { isArray, isObject, isString, isPrimitive } from "../types/is.mjs";
|
13
|
-
import { getDocumentTranslations, Translations } from "../i18n/translations.mjs";
|
14
13
|
import {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
getDocumentTranslations,
|
15
|
+
Translations,
|
16
|
+
} from "../i18n/translations.mjs";
|
17
|
+
import {
|
18
|
+
validateFunction,
|
19
|
+
validateInteger,
|
20
|
+
validateObject,
|
21
|
+
validatePrimitive,
|
22
|
+
validateString,
|
23
|
+
validateBoolean,
|
21
24
|
} from "../types/validate.mjs";
|
22
25
|
import { clone } from "../util/clone.mjs";
|
23
26
|
import { Pathfinder } from "./pathfinder.mjs";
|
@@ -42,53 +45,53 @@ export { Transformer };
|
|
42
45
|
* @memberOf Monster.Data
|
43
46
|
*/
|
44
47
|
class Transformer extends Base {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
48
|
+
/**
|
49
|
+
*
|
50
|
+
* @param {string} definition
|
51
|
+
*/
|
52
|
+
constructor(definition) {
|
53
|
+
super();
|
54
|
+
this.args = disassemble(definition);
|
55
|
+
this.command = this.args.shift();
|
56
|
+
this.callbacks = new Map();
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
*
|
61
|
+
* @param {string} name
|
62
|
+
* @param {function} callback
|
63
|
+
* @param {object} context
|
64
|
+
* @returns {Transformer}
|
65
|
+
* @throws {TypeError} value is not a string
|
66
|
+
* @throws {TypeError} value is not a function
|
67
|
+
*/
|
68
|
+
setCallback(name, callback, context) {
|
69
|
+
validateString(name);
|
70
|
+
validateFunction(callback);
|
71
|
+
|
72
|
+
if (context !== undefined) {
|
73
|
+
validateObject(context);
|
74
|
+
}
|
75
|
+
|
76
|
+
this.callbacks.set(name, {
|
77
|
+
callback: callback,
|
78
|
+
context: context,
|
79
|
+
});
|
80
|
+
|
81
|
+
return this;
|
82
|
+
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
*
|
86
|
+
* @param {*} value
|
87
|
+
* @returns {*}
|
88
|
+
* @throws {Error} unknown command
|
89
|
+
* @throws {TypeError} unsupported type
|
90
|
+
* @throws {Error} type not supported
|
91
|
+
*/
|
92
|
+
run(value) {
|
93
|
+
return transform.apply(this, [value]);
|
94
|
+
}
|
92
95
|
}
|
93
96
|
|
94
97
|
/**
|
@@ -98,41 +101,41 @@ class Transformer extends Base {
|
|
98
101
|
* @private
|
99
102
|
*/
|
100
103
|
function disassemble(command) {
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
104
|
+
validateString(command);
|
105
|
+
|
106
|
+
const placeholder = new Map();
|
107
|
+
const regex = /((?<pattern>\\(?<char>.)){1})/gim;
|
108
|
+
|
109
|
+
// The separator for args must be escaped
|
110
|
+
// undefined string which should not occur normally and is also not a regex
|
111
|
+
const result = command.matchAll(regex);
|
112
|
+
|
113
|
+
for (const m of result) {
|
114
|
+
const g = m?.["groups"];
|
115
|
+
if (!isObject(g)) {
|
116
|
+
continue;
|
117
|
+
}
|
118
|
+
|
119
|
+
const p = g?.["pattern"];
|
120
|
+
const c = g?.["char"];
|
121
|
+
|
122
|
+
if (p && c) {
|
123
|
+
const r = `__${new ID().toString()}__`;
|
124
|
+
placeholder.set(r, c);
|
125
|
+
command = command.replace(p, r);
|
126
|
+
}
|
127
|
+
}
|
128
|
+
let parts = command.split(":");
|
129
|
+
|
130
|
+
parts = parts.map(function (value) {
|
131
|
+
let v = value.trim();
|
132
|
+
for (const k of placeholder) {
|
133
|
+
v = v.replace(k[0], k[1]);
|
134
|
+
}
|
135
|
+
return v;
|
136
|
+
});
|
137
|
+
|
138
|
+
return parts;
|
136
139
|
}
|
137
140
|
|
138
141
|
/**
|
@@ -143,12 +146,12 @@ function disassemble(command) {
|
|
143
146
|
* @private
|
144
147
|
*/
|
145
148
|
function convertToString(value) {
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
+
if (isObject(value) && value.hasOwnProperty("toString")) {
|
150
|
+
value = value.toString();
|
151
|
+
}
|
149
152
|
|
150
|
-
|
151
|
-
|
153
|
+
validateString(value);
|
154
|
+
return value;
|
152
155
|
}
|
153
156
|
|
154
157
|
/**
|
@@ -162,636 +165,649 @@ function convertToString(value) {
|
|
162
165
|
* @throws {Error} missing key parameter
|
163
166
|
*/
|
164
167
|
function transform(value) {
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
168
|
+
const console = getGlobalObject("console");
|
169
|
+
|
170
|
+
const args = clone(this.args);
|
171
|
+
let key;
|
172
|
+
let defaultValue;
|
173
|
+
|
174
|
+
let translations;
|
175
|
+
let date;
|
176
|
+
let locale;
|
177
|
+
let timestamp;
|
178
|
+
let map;
|
179
|
+
let keyValue;
|
180
|
+
|
181
|
+
switch (this.command) {
|
182
|
+
case "static":
|
183
|
+
return this.args.join(":");
|
184
|
+
|
185
|
+
case "tolower":
|
186
|
+
case "strtolower":
|
187
|
+
case "tolowercase":
|
188
|
+
validateString(value);
|
189
|
+
return value.toLowerCase();
|
190
|
+
|
191
|
+
case "contains":
|
192
|
+
if (isString(value)) {
|
193
|
+
return value.includes(args[0]);
|
194
|
+
}
|
195
|
+
|
196
|
+
if (isArray(value)) {
|
197
|
+
return value.includes(args[0]);
|
198
|
+
}
|
199
|
+
|
200
|
+
if (isObject(value)) {
|
201
|
+
return value.hasOwnProperty(args[0]);
|
202
|
+
}
|
203
|
+
|
204
|
+
return false;
|
205
|
+
|
206
|
+
case "has-entries":
|
207
|
+
case "hasentries":
|
208
|
+
if (isObject(value)) {
|
209
|
+
return Object.keys(value).length > 0;
|
210
|
+
}
|
211
|
+
|
212
|
+
if (isArray(value)) {
|
213
|
+
return value.length > 0;
|
214
|
+
}
|
215
|
+
|
216
|
+
return false;
|
217
|
+
|
218
|
+
case "isundefined":
|
219
|
+
case "is-undefined":
|
220
|
+
return value === undefined;
|
221
|
+
|
222
|
+
case "isnull":
|
223
|
+
case "is-null":
|
224
|
+
return value === null;
|
225
|
+
|
226
|
+
case "isset":
|
227
|
+
case "is-set":
|
228
|
+
return value !== undefined && value !== null;
|
229
|
+
|
230
|
+
case "isnumber":
|
231
|
+
case "is-number":
|
232
|
+
return isPrimitive(value) && !isNaN(value);
|
233
|
+
|
234
|
+
case "isinteger":
|
235
|
+
case "is-integer":
|
236
|
+
return isPrimitive(value) && !isNaN(value) && value % 1 === 0;
|
237
|
+
|
238
|
+
case "isfloat":
|
239
|
+
case "is-float":
|
240
|
+
return isPrimitive(value) && !isNaN(value) && value % 1 !== 0;
|
241
|
+
|
242
|
+
case "isobject":
|
243
|
+
case "is-object":
|
244
|
+
return isObject(value);
|
245
|
+
|
246
|
+
case "isarray":
|
247
|
+
case "is-array":
|
248
|
+
return Array.isArray(value);
|
249
|
+
|
250
|
+
case "not":
|
251
|
+
validateBoolean(value);
|
252
|
+
return !value;
|
253
|
+
|
254
|
+
case "toupper":
|
255
|
+
case "strtoupper":
|
256
|
+
case "touppercase":
|
257
|
+
validateString(value);
|
258
|
+
return value.toUpperCase();
|
259
|
+
|
260
|
+
case "tostring":
|
261
|
+
return `${value}`;
|
262
|
+
|
263
|
+
case "tointeger":
|
264
|
+
const n = parseInt(value);
|
265
|
+
validateInteger(n);
|
266
|
+
return n;
|
267
|
+
|
268
|
+
case "to-json":
|
269
|
+
case "tojson":
|
270
|
+
return JSON.stringify(value);
|
271
|
+
|
272
|
+
case "from-json":
|
273
|
+
case "fromjson":
|
274
|
+
return JSON.parse(value);
|
275
|
+
|
276
|
+
case "trim":
|
277
|
+
validateString(value);
|
278
|
+
return value.trim();
|
279
|
+
|
280
|
+
case "rawurlencode":
|
281
|
+
validateString(value);
|
282
|
+
return encodeURIComponent(value)
|
283
|
+
.replace(/!/g, "%21")
|
284
|
+
.replace(/'/g, "%27")
|
285
|
+
.replace(/\(/g, "%28")
|
286
|
+
.replace(/\)/g, "%29")
|
287
|
+
.replace(/\*/g, "%2A");
|
288
|
+
|
289
|
+
case "call":
|
290
|
+
/**
|
291
|
+
* callback-definition
|
292
|
+
* function callback(value, ...args) {
|
293
|
+
* return value;
|
294
|
+
* }
|
295
|
+
*/
|
296
|
+
|
297
|
+
let callback;
|
298
|
+
const callbackName = args.shift();
|
299
|
+
let context = getGlobal();
|
300
|
+
|
301
|
+
if (isObject(value) && value.hasOwnProperty(callbackName)) {
|
302
|
+
callback = value[callbackName];
|
303
|
+
} else if (this.callbacks.has(callbackName)) {
|
304
|
+
const s = this.callbacks.get(callbackName);
|
305
|
+
callback = s?.["callback"];
|
306
|
+
context = s?.["context"];
|
307
|
+
} else if (
|
308
|
+
typeof window === "object" &&
|
309
|
+
window.hasOwnProperty(callbackName)
|
310
|
+
) {
|
311
|
+
callback = window[callbackName];
|
312
|
+
}
|
313
|
+
validateFunction(callback);
|
314
|
+
|
315
|
+
args.unshift(value);
|
316
|
+
return callback.call(context, ...args);
|
317
|
+
|
318
|
+
case "plain":
|
319
|
+
case "plaintext":
|
320
|
+
validateString(value);
|
321
|
+
const doc = new DOMParser().parseFromString(value, "text/html");
|
322
|
+
return doc.body.textContent || "";
|
323
|
+
|
324
|
+
case "if":
|
325
|
+
case "?":
|
326
|
+
validatePrimitive(value);
|
327
|
+
|
328
|
+
let trueStatement = args.shift() || undefined;
|
329
|
+
let falseStatement = args.shift() || undefined;
|
330
|
+
|
331
|
+
if (trueStatement === "value") {
|
332
|
+
trueStatement = value;
|
333
|
+
}
|
334
|
+
if (trueStatement === "\\value") {
|
335
|
+
trueStatement = "value";
|
336
|
+
}
|
337
|
+
|
338
|
+
if (trueStatement === "\\undefined") {
|
339
|
+
trueStatement = undefined;
|
340
|
+
}
|
341
|
+
|
342
|
+
if (trueStatement === "\\null") {
|
343
|
+
trueStatement = null;
|
344
|
+
}
|
345
|
+
|
346
|
+
if (falseStatement === "value") {
|
347
|
+
falseStatement = value;
|
348
|
+
}
|
349
|
+
if (falseStatement === "\\value") {
|
350
|
+
falseStatement = "value";
|
351
|
+
}
|
352
|
+
|
353
|
+
if (falseStatement === "\\undefined") {
|
354
|
+
falseStatement = undefined;
|
355
|
+
}
|
356
|
+
|
357
|
+
if (falseStatement === "\\null") {
|
358
|
+
falseStatement = null;
|
359
|
+
}
|
360
|
+
|
361
|
+
const condition =
|
362
|
+
(value !== undefined &&
|
363
|
+
value !== "" &&
|
364
|
+
value !== "off" &&
|
365
|
+
value !== "false" &&
|
366
|
+
value !== false) ||
|
367
|
+
value === "on" ||
|
368
|
+
value === "true" ||
|
369
|
+
value === true;
|
370
|
+
return condition ? trueStatement : falseStatement;
|
371
|
+
|
372
|
+
case "ucfirst":
|
373
|
+
validateString(value);
|
374
|
+
|
375
|
+
const firstchar = value.charAt(0).toUpperCase();
|
376
|
+
return firstchar + value.substr(1);
|
377
|
+
case "ucwords":
|
378
|
+
validateString(value);
|
379
|
+
|
380
|
+
return value.replace(
|
381
|
+
/^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g,
|
382
|
+
function (v) {
|
383
|
+
return v.toUpperCase();
|
384
|
+
},
|
385
|
+
);
|
386
|
+
|
387
|
+
case "count":
|
388
|
+
case "length":
|
389
|
+
if (
|
390
|
+
(isString(value) || isObject(value) || isArray(value)) &&
|
391
|
+
value.hasOwnProperty("length")
|
392
|
+
) {
|
393
|
+
return value.length;
|
394
|
+
}
|
395
|
+
|
396
|
+
throw new TypeError(`unsupported type ${typeof value}`);
|
397
|
+
|
398
|
+
case "to-base64":
|
399
|
+
case "btoa":
|
400
|
+
case "base64":
|
401
|
+
return btoa(convertToString(value));
|
402
|
+
|
403
|
+
case "atob":
|
404
|
+
case "from-base64":
|
405
|
+
return atob(convertToString(value));
|
406
|
+
|
407
|
+
case "empty":
|
408
|
+
return "";
|
409
|
+
|
410
|
+
case "undefined":
|
411
|
+
return undefined;
|
412
|
+
|
413
|
+
case "debug":
|
414
|
+
if (isObject(console)) {
|
415
|
+
console.log(value);
|
416
|
+
}
|
417
|
+
|
418
|
+
return value;
|
419
|
+
|
420
|
+
case "prefix":
|
421
|
+
validateString(value);
|
422
|
+
const prefix = args?.[0];
|
423
|
+
return prefix + value;
|
424
|
+
|
425
|
+
case "suffix":
|
426
|
+
validateString(value);
|
427
|
+
const suffix = args?.[0];
|
428
|
+
return value + suffix;
|
429
|
+
|
430
|
+
case "uniqid":
|
431
|
+
return new ID().toString();
|
432
|
+
|
433
|
+
case "first-key":
|
434
|
+
case "last-key":
|
435
|
+
case "nth-last-key":
|
436
|
+
case "nth-key":
|
437
|
+
if (!isObject(value)) {
|
438
|
+
throw new Error("type not supported");
|
439
|
+
}
|
440
|
+
|
441
|
+
const keys = Object.keys(value).sort();
|
442
|
+
|
443
|
+
if (this.command === "first-key") {
|
444
|
+
key = 0;
|
445
|
+
} else if (this.command === "last-key") {
|
446
|
+
key = keys.length - 1;
|
447
|
+
} else {
|
448
|
+
key = validateInteger(parseInt(args.shift()));
|
449
|
+
|
450
|
+
if (this.command === "nth-last-key") {
|
451
|
+
key = keys.length - key - 1;
|
452
|
+
}
|
453
|
+
}
|
454
|
+
|
455
|
+
defaultValue = args.shift() || "";
|
456
|
+
|
457
|
+
const useKey = keys?.[key];
|
458
|
+
|
459
|
+
if (value?.[useKey]) {
|
460
|
+
return value?.[useKey];
|
461
|
+
}
|
462
|
+
|
463
|
+
return defaultValue;
|
464
|
+
|
465
|
+
case "key":
|
466
|
+
case "property":
|
467
|
+
case "index":
|
468
|
+
key = args.shift() || undefined;
|
469
|
+
|
470
|
+
if (key === undefined) {
|
471
|
+
throw new Error("missing key parameter");
|
472
|
+
}
|
473
|
+
|
474
|
+
defaultValue = args.shift() || undefined;
|
475
|
+
|
476
|
+
if (value instanceof Map) {
|
477
|
+
if (!value.has(key)) {
|
478
|
+
return defaultValue;
|
479
|
+
}
|
480
|
+
return value.get(key);
|
481
|
+
}
|
482
|
+
|
483
|
+
if (isObject(value) || isArray(value)) {
|
484
|
+
if (value?.[key]) {
|
485
|
+
return value?.[key];
|
486
|
+
}
|
487
|
+
|
488
|
+
return defaultValue;
|
489
|
+
}
|
490
|
+
|
491
|
+
throw new Error("type not supported");
|
492
|
+
|
493
|
+
case "path-exists":
|
494
|
+
key = args.shift();
|
495
|
+
if (key === undefined) {
|
496
|
+
throw new Error("missing key parameter");
|
497
|
+
}
|
498
|
+
|
499
|
+
return new Pathfinder(value).exists(key);
|
500
|
+
|
501
|
+
case "concat":
|
502
|
+
const pf2 = new Pathfinder(value);
|
503
|
+
let concat = "";
|
504
|
+
while (args.length > 0) {
|
505
|
+
key = args.shift();
|
506
|
+
if (key === undefined) {
|
507
|
+
throw new Error("missing key parameter");
|
508
|
+
}
|
509
|
+
|
510
|
+
// add empty strings
|
511
|
+
if (isString(key) && key.trim() === "") {
|
512
|
+
concat += key;
|
513
|
+
continue;
|
514
|
+
}
|
515
|
+
|
516
|
+
if (!pf2.exists(key)) {
|
517
|
+
concat += key;
|
518
|
+
continue;
|
519
|
+
}
|
520
|
+
const v = pf2.getVia(key);
|
521
|
+
if (!isPrimitive(v)) {
|
522
|
+
throw new Error("value is not primitive");
|
523
|
+
}
|
524
|
+
|
525
|
+
concat += v;
|
526
|
+
}
|
527
|
+
|
528
|
+
return concat;
|
529
|
+
case "path":
|
530
|
+
key = args.shift();
|
531
|
+
if (key === undefined) {
|
532
|
+
throw new Error("missing key parameter");
|
533
|
+
}
|
534
|
+
|
535
|
+
const pf = new Pathfinder(value);
|
536
|
+
|
537
|
+
if (!pf.exists(key)) {
|
538
|
+
return undefined;
|
539
|
+
}
|
540
|
+
|
541
|
+
return pf.getVia(key);
|
542
|
+
|
543
|
+
case "substring":
|
544
|
+
validateString(value);
|
545
|
+
|
546
|
+
const start = parseInt(args[0]) || 0;
|
547
|
+
const end = (parseInt(args[1]) || 0) + start;
|
548
|
+
|
549
|
+
return value.substring(start, end);
|
550
|
+
|
551
|
+
case "nop":
|
552
|
+
return value;
|
553
|
+
|
554
|
+
case "??":
|
555
|
+
case "default":
|
556
|
+
if (value !== undefined && value !== null) {
|
557
|
+
return value;
|
558
|
+
}
|
559
|
+
|
560
|
+
defaultValue = args.shift();
|
561
|
+
let defaultType = args.shift();
|
562
|
+
if (defaultType === undefined) {
|
563
|
+
defaultType = "string";
|
564
|
+
}
|
565
|
+
|
566
|
+
switch (defaultType) {
|
567
|
+
case "int":
|
568
|
+
case "integer":
|
569
|
+
return parseInt(defaultValue);
|
570
|
+
case "float":
|
571
|
+
return parseFloat(defaultValue);
|
572
|
+
case "undefined":
|
573
|
+
return undefined;
|
574
|
+
case "bool":
|
575
|
+
case "boolean":
|
576
|
+
defaultValue = defaultValue.toLowerCase();
|
577
|
+
return (
|
578
|
+
(defaultValue !== "undefined" &&
|
579
|
+
defaultValue !== "" &&
|
580
|
+
defaultValue !== "off" &&
|
581
|
+
defaultValue !== "false" &&
|
582
|
+
defaultValue !== "false") ||
|
583
|
+
defaultValue === "on" ||
|
584
|
+
defaultValue === "true" ||
|
585
|
+
defaultValue === "true"
|
586
|
+
);
|
587
|
+
case "string":
|
588
|
+
return `${defaultValue}`;
|
589
|
+
case "object":
|
590
|
+
return JSON.parse(atob(defaultValue));
|
591
|
+
}
|
592
|
+
|
593
|
+
throw new Error("type not supported");
|
594
|
+
|
595
|
+
case "map":
|
596
|
+
map = new Map();
|
597
|
+
while (args.length > 0) {
|
598
|
+
keyValue = args.shift();
|
599
|
+
if (keyValue === undefined) {
|
600
|
+
throw new Error("missing key parameter");
|
601
|
+
}
|
602
|
+
|
603
|
+
keyValue = keyValue.split("=");
|
604
|
+
map.set(keyValue[0], keyValue[1]);
|
605
|
+
}
|
606
|
+
|
607
|
+
return map.get(value);
|
608
|
+
|
609
|
+
case "equals":
|
610
|
+
if (args.length === 0) {
|
611
|
+
throw new Error("missing value parameter");
|
612
|
+
}
|
613
|
+
|
614
|
+
validatePrimitive(value);
|
615
|
+
|
616
|
+
const equalsValue = args.shift();
|
617
|
+
|
618
|
+
/**
|
619
|
+
* The history of “typeof null”
|
620
|
+
* https://2ality.com/2013/10/typeof-null.html
|
621
|
+
* In JavaScript, typeof null is 'object', which incorrectly suggests
|
622
|
+
* that null is an object.
|
623
|
+
*/
|
624
|
+
if (value === null) {
|
625
|
+
if (equalsValue === "null") {
|
626
|
+
return true;
|
627
|
+
}
|
628
|
+
return false;
|
629
|
+
}
|
630
|
+
|
631
|
+
const typeOfValue = typeof value;
|
632
|
+
|
633
|
+
switch (typeOfValue) {
|
634
|
+
case "string":
|
635
|
+
return value === equalsValue;
|
636
|
+
case "number":
|
637
|
+
return value === parseFloat(equalsValue);
|
638
|
+
case "boolean":
|
639
|
+
return value === (equalsValue === "true" || equalsValue === "on");
|
640
|
+
case "undefined":
|
641
|
+
return equalsValue === "undefined";
|
642
|
+
default:
|
643
|
+
throw new Error("type not supported");
|
644
|
+
}
|
645
|
+
|
646
|
+
case "money":
|
647
|
+
case "currency":
|
648
|
+
try {
|
649
|
+
locale = getLocaleOfDocument();
|
650
|
+
} catch (e) {
|
651
|
+
throw new Error(`unsupported locale or missing format (${e.message})`);
|
652
|
+
}
|
653
|
+
|
654
|
+
const currency = value.substring(0, 3);
|
655
|
+
if (!currency) {
|
656
|
+
throw new Error("missing currency parameter");
|
657
|
+
}
|
658
|
+
|
659
|
+
const maximumFractionDigits = args?.[0] || 2;
|
660
|
+
const roundingIncrement = args?.[1] || 5;
|
661
|
+
|
662
|
+
const nf = new Intl.NumberFormat(locale, {
|
663
|
+
style: "currency",
|
664
|
+
currency: currency,
|
665
|
+
maximumFractionDigits: maximumFractionDigits,
|
666
|
+
roundingIncrement: roundingIncrement,
|
667
|
+
});
|
668
|
+
|
669
|
+
return nf.format(value.substring(3));
|
670
|
+
|
671
|
+
case "timestamp":
|
672
|
+
date = new Date(value);
|
673
|
+
timestamp = date.getTime();
|
674
|
+
if (isNaN(timestamp)) {
|
675
|
+
throw new Error("invalid date");
|
676
|
+
}
|
677
|
+
return timestamp;
|
678
|
+
|
679
|
+
case "time":
|
680
|
+
date = new Date(value);
|
681
|
+
if (isNaN(date.getTime())) {
|
682
|
+
throw new Error("invalid date");
|
683
|
+
}
|
684
|
+
|
685
|
+
try {
|
686
|
+
locale = getLocaleOfDocument();
|
687
|
+
return date.toLocaleTimeString(locale);
|
688
|
+
} catch (e) {
|
689
|
+
throw new Error(`unsupported locale or missing format (${e.message})`);
|
690
|
+
}
|
691
|
+
|
692
|
+
case "datetimeformat":
|
693
|
+
date = new Date(value);
|
694
|
+
if (isNaN(date.getTime())) {
|
695
|
+
throw new Error("invalid date");
|
696
|
+
}
|
697
|
+
|
698
|
+
const options = {
|
699
|
+
dateStyle: args.shift() || "medium",
|
700
|
+
timeStyle: args.shift() || "medium",
|
701
|
+
};
|
702
|
+
|
703
|
+
try {
|
704
|
+
locale = getLocaleOfDocument();
|
705
|
+
return new Intl.DateTimeFormat(locale, options).format(date);
|
706
|
+
} catch (e) {
|
707
|
+
throw new Error(`unsupported locale or missing format (${e.message})`);
|
708
|
+
}
|
709
|
+
|
710
|
+
case "datetime":
|
711
|
+
date = new Date(value);
|
712
|
+
if (isNaN(date.getTime())) {
|
713
|
+
throw new Error("invalid date");
|
714
|
+
}
|
715
|
+
|
716
|
+
try {
|
717
|
+
locale = getLocaleOfDocument();
|
718
|
+
return date.toLocaleString(locale);
|
719
|
+
} catch (e) {
|
720
|
+
throw new Error(`unsupported locale or missing format (${e.message})`);
|
721
|
+
}
|
722
|
+
|
723
|
+
case "date":
|
724
|
+
date = new Date(value);
|
725
|
+
if (isNaN(date.getTime())) {
|
726
|
+
throw new Error("invalid date");
|
727
|
+
}
|
728
|
+
|
729
|
+
try {
|
730
|
+
locale = getLocaleOfDocument();
|
731
|
+
return date.toLocaleDateString(locale);
|
732
|
+
} catch (e) {
|
733
|
+
throw new Error(`unsupported locale or missing format (${e.message})`);
|
734
|
+
}
|
735
|
+
|
736
|
+
case "year":
|
737
|
+
date = new Date(value);
|
738
|
+
if (isNaN(date.getTime())) {
|
739
|
+
throw new Error("invalid date");
|
740
|
+
}
|
741
|
+
|
742
|
+
return date.getFullYear();
|
743
|
+
|
744
|
+
case "month":
|
745
|
+
date = new Date(value);
|
746
|
+
if (isNaN(date.getTime())) {
|
747
|
+
throw new Error("invalid date");
|
748
|
+
}
|
749
|
+
|
750
|
+
return date.getMonth() + 1;
|
751
|
+
|
752
|
+
case "day":
|
753
|
+
date = new Date(value);
|
754
|
+
if (isNaN(date.getTime())) {
|
755
|
+
throw new Error("invalid date");
|
756
|
+
}
|
757
|
+
|
758
|
+
return date.getDate();
|
759
|
+
|
760
|
+
case "weekday":
|
761
|
+
date = new Date(value);
|
762
|
+
if (isNaN(date.getTime())) {
|
763
|
+
throw new Error("invalid date");
|
764
|
+
}
|
765
|
+
|
766
|
+
return date.getDay();
|
767
|
+
|
768
|
+
case "hour":
|
769
|
+
case "hours":
|
770
|
+
date = new Date(value);
|
771
|
+
if (isNaN(date.getTime())) {
|
772
|
+
throw new Error("invalid date");
|
773
|
+
}
|
774
|
+
|
775
|
+
return date.getHours();
|
776
|
+
|
777
|
+
case "minute":
|
778
|
+
case "minutes":
|
779
|
+
date = new Date(value);
|
780
|
+
if (isNaN(date.getTime())) {
|
781
|
+
throw new Error("invalid date");
|
782
|
+
}
|
783
|
+
|
784
|
+
return date.getMinutes();
|
785
|
+
|
786
|
+
case "second":
|
787
|
+
case "seconds":
|
788
|
+
date = new Date(value);
|
789
|
+
if (isNaN(date.getTime())) {
|
790
|
+
throw new Error("invalid date");
|
791
|
+
}
|
792
|
+
|
793
|
+
return date.getSeconds();
|
794
|
+
|
795
|
+
case "i18n":
|
796
|
+
case "translation":
|
797
|
+
translations = getDocumentTranslations();
|
798
|
+
if (!(translations instanceof Translations)) {
|
799
|
+
throw new Error("missing translations");
|
800
|
+
}
|
801
|
+
|
802
|
+
key = args.shift() || undefined;
|
803
|
+
if (key === undefined) {
|
804
|
+
key = value;
|
805
|
+
}
|
806
|
+
|
807
|
+
defaultValue = args.shift() || undefined;
|
808
|
+
return translations.getText(key, defaultValue);
|
809
|
+
|
810
|
+
default:
|
811
|
+
throw new Error(`unknown command ${this.command}`);
|
812
|
+
}
|
797
813
|
}
|