@domql/utils 2.5.187 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/array.js +26 -13
  2. package/cache.js +4 -0
  3. package/component.js +10 -227
  4. package/cookie.js +27 -24
  5. package/dist/cjs/array.js +30 -16
  6. package/dist/cjs/cache.js +26 -0
  7. package/dist/cjs/component.js +16 -226
  8. package/dist/cjs/cookie.js +19 -24
  9. package/dist/cjs/element.js +137 -0
  10. package/dist/cjs/events.js +37 -0
  11. package/dist/cjs/extends.js +351 -0
  12. package/dist/cjs/function.js +2 -4
  13. package/dist/cjs/if.js +30 -0
  14. package/dist/cjs/index.js +25 -15
  15. package/dist/cjs/key.js +6 -1
  16. package/dist/cjs/keys.js +178 -0
  17. package/dist/cjs/log.js +1 -2
  18. package/dist/cjs/methods.js +305 -0
  19. package/dist/cjs/object.js +89 -237
  20. package/dist/cjs/props.js +220 -0
  21. package/dist/cjs/scope.js +28 -0
  22. package/dist/cjs/state.js +175 -0
  23. package/dist/cjs/string.js +27 -16
  24. package/dist/cjs/types.js +2 -4
  25. package/dist/cjs/update.js +42 -0
  26. package/dist/esm/array.js +30 -16
  27. package/dist/esm/cache.js +6 -0
  28. package/dist/esm/component.js +17 -245
  29. package/dist/esm/cookie.js +19 -24
  30. package/dist/esm/element.js +135 -0
  31. package/dist/esm/events.js +17 -0
  32. package/dist/esm/extends.js +349 -0
  33. package/dist/esm/function.js +2 -4
  34. package/dist/esm/if.js +10 -0
  35. package/dist/esm/index.js +10 -0
  36. package/dist/esm/key.js +6 -1
  37. package/dist/esm/keys.js +158 -0
  38. package/dist/esm/log.js +1 -2
  39. package/dist/esm/methods.js +285 -0
  40. package/dist/esm/object.js +90 -239
  41. package/dist/esm/props.js +216 -0
  42. package/dist/esm/scope.js +8 -0
  43. package/dist/esm/state.js +185 -0
  44. package/dist/esm/string.js +27 -16
  45. package/dist/esm/types.js +2 -4
  46. package/dist/esm/update.js +22 -0
  47. package/element.js +149 -0
  48. package/env.js +5 -2
  49. package/events.js +17 -0
  50. package/extends.js +425 -0
  51. package/if.js +14 -0
  52. package/index.js +10 -0
  53. package/key.js +6 -0
  54. package/keys.js +157 -0
  55. package/log.js +4 -1
  56. package/methods.js +315 -0
  57. package/node.js +21 -13
  58. package/object.js +121 -235
  59. package/package.json +3 -3
  60. package/props.js +249 -0
  61. package/scope.js +8 -0
  62. package/state.js +208 -0
  63. package/string.js +66 -30
  64. package/update.js +27 -0
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var props_exports = {};
20
+ __export(props_exports, {
21
+ applyProps: () => applyProps,
22
+ createProps: () => createProps,
23
+ createPropsStack: () => createPropsStack,
24
+ inheritParentProps: () => inheritParentProps,
25
+ initProps: () => initProps,
26
+ objectizeStringProperty: () => objectizeStringProperty,
27
+ pickupElementFromProps: () => pickupElementFromProps,
28
+ pickupPropsFromElement: () => pickupPropsFromElement,
29
+ propExists: () => propExists,
30
+ propertizeElement: () => propertizeElement,
31
+ removeDuplicateProps: () => removeDuplicateProps,
32
+ setPropsPrototype: () => setPropsPrototype,
33
+ syncProps: () => syncProps,
34
+ update: () => update,
35
+ updateProps: () => updateProps
36
+ });
37
+ module.exports = __toCommonJS(props_exports);
38
+ var import_keys = require("./keys.js");
39
+ var import_events = require("./events.js");
40
+ var import_object = require("./object.js");
41
+ var import_types = require("./types.js");
42
+ const createProps = (element, parent, key) => {
43
+ const { props, __ref: ref } = element;
44
+ ref.__propsStack = [];
45
+ if (props) ref.__initialProps = props;
46
+ else return {};
47
+ if (!(0, import_types.isObjectLike)(props)) {
48
+ ref.__propsStack.push(props);
49
+ return {};
50
+ }
51
+ return { ...props };
52
+ };
53
+ function pickupPropsFromElement(element, opts = {}) {
54
+ var _a, _b, _c;
55
+ const cachedKeys = opts.cachedKeys || [];
56
+ for (const key in element) {
57
+ const value = element[key];
58
+ const hasDefine = (0, import_types.isObject)((_a = element.define) == null ? void 0 : _a[key]);
59
+ const hasGlobalDefine = (0, import_types.isObject)((_c = (_b = element.context) == null ? void 0 : _b.define) == null ? void 0 : _c[key]);
60
+ const isElement = /^[A-Z]/.test(key) || /^\d+$/.test(key);
61
+ const isBuiltin = import_keys.DOMQ_PROPERTIES.includes(key);
62
+ if (!isElement && !isBuiltin && !hasDefine && !hasGlobalDefine) {
63
+ element.props[key] = value;
64
+ delete element[key];
65
+ cachedKeys.push(key);
66
+ }
67
+ }
68
+ return element;
69
+ }
70
+ function pickupElementFromProps(element, opts) {
71
+ var _a, _b, _c;
72
+ const cachedKeys = opts.cachedKeys || [];
73
+ for (const key in element.props) {
74
+ const value = element.props[key];
75
+ const isEvent = key.startsWith("on") && key.length > 2;
76
+ const isFn = (0, import_types.isFunction)(value);
77
+ if (isEvent && isFn) {
78
+ (0, import_events.addEventFromProps)(key, element);
79
+ delete element.props[key];
80
+ continue;
81
+ }
82
+ if (cachedKeys.includes(key)) continue;
83
+ const hasDefine = (0, import_types.isObject)((_a = element.define) == null ? void 0 : _a[key]);
84
+ const hasGlobalDefine = (0, import_types.isObject)((_c = (_b = element.context) == null ? void 0 : _b.define) == null ? void 0 : _c[key]);
85
+ const isElement = /^[A-Z]/.test(key) || /^\d+$/.test(key);
86
+ const isBuiltin = import_keys.DOMQ_PROPERTIES.includes(key);
87
+ if (isElement || isBuiltin || hasDefine || hasGlobalDefine) {
88
+ element[key] = value;
89
+ delete element.props[key];
90
+ }
91
+ }
92
+ return element;
93
+ }
94
+ function propertizeElement(element, opts = {}) {
95
+ const cachedKeys = [];
96
+ pickupPropsFromElement(element, { cachedKeys });
97
+ pickupElementFromProps(element, { cachedKeys });
98
+ return element;
99
+ }
100
+ const objectizeStringProperty = (propValue) => {
101
+ if ((0, import_types.is)(propValue)("string", "number")) {
102
+ return { inheritedString: propValue };
103
+ }
104
+ return propValue;
105
+ };
106
+ const propExists = (prop, stack) => {
107
+ if (!prop || !stack.length) return false;
108
+ const key = (0, import_types.isObject)(prop) ? JSON.stringify(prop) : prop;
109
+ return stack.some((existing) => {
110
+ const existingKey = (0, import_types.isObject)(existing) ? JSON.stringify(existing) : existing;
111
+ return existingKey === key;
112
+ });
113
+ };
114
+ const inheritParentProps = (element, parent) => {
115
+ var _a;
116
+ const { __ref: ref } = element;
117
+ const propsStack = ref.__propsStack || [];
118
+ const parentProps = parent.props;
119
+ if (!parentProps) return propsStack;
120
+ const matchParentKeyProps = parentProps[element.key];
121
+ const matchParentChildProps = parentProps.childProps;
122
+ const ignoreChildProps = (_a = element.props) == null ? void 0 : _a.ignoreChildProps;
123
+ if (matchParentChildProps && !ignoreChildProps) {
124
+ const childProps = objectizeStringProperty(matchParentChildProps);
125
+ propsStack.unshift(childProps);
126
+ }
127
+ if (matchParentKeyProps) {
128
+ const keyProps = objectizeStringProperty(matchParentKeyProps);
129
+ propsStack.unshift(keyProps);
130
+ }
131
+ return propsStack;
132
+ };
133
+ async function update(props, options) {
134
+ const element = this.__element;
135
+ await element.update({ props }, options);
136
+ }
137
+ function setPropsPrototype(element) {
138
+ const methods = { update: update.bind(element.props), __element: element };
139
+ Object.setPrototypeOf(element.props, methods);
140
+ }
141
+ const removeDuplicateProps = (propsStack) => {
142
+ const seen = /* @__PURE__ */ new Set();
143
+ return propsStack.filter((prop) => {
144
+ if (!prop || import_keys.PROPS_METHODS.includes(prop)) return false;
145
+ const key = (0, import_types.isObject)(prop) ? JSON.stringify(prop) : prop;
146
+ if (seen.has(key)) return false;
147
+ seen.add(key);
148
+ return true;
149
+ });
150
+ };
151
+ const syncProps = (propsStack, element, opts) => {
152
+ element.props = propsStack.reduce((mergedProps, v) => {
153
+ if (import_keys.PROPS_METHODS.includes(v)) return mergedProps;
154
+ while ((0, import_types.isFunction)(v)) v = (0, import_object.exec)(v, element);
155
+ return (0, import_object.deepMerge)(mergedProps, (0, import_object.deepClone)(v, { exclude: import_keys.PROPS_METHODS }));
156
+ }, {});
157
+ setPropsPrototype(element);
158
+ return element.props;
159
+ };
160
+ const createPropsStack = (element, parent) => {
161
+ const { props, __ref: ref } = element;
162
+ let propsStack = ref.__propsStack || [];
163
+ if (parent && parent.props) {
164
+ const parentStack = inheritParentProps(element, parent);
165
+ propsStack = [...parentStack];
166
+ }
167
+ if ((0, import_types.isObject)(props)) propsStack.push(props);
168
+ else if (props === "inherit" && (parent == null ? void 0 : parent.props)) propsStack.push(parent.props);
169
+ else if (props) propsStack.push(props);
170
+ if ((0, import_types.isArray)(ref.__extendsStack)) {
171
+ ref.__extendsStack.forEach((_extends) => {
172
+ if (_extends.props && _extends.props !== props) {
173
+ propsStack.push(_extends.props);
174
+ }
175
+ });
176
+ }
177
+ ref.__propsStack = removeDuplicateProps(propsStack);
178
+ return ref.__propsStack;
179
+ };
180
+ const applyProps = (element, parent) => {
181
+ const { __ref: ref } = element;
182
+ const propsStack = createPropsStack(element, parent);
183
+ if (propsStack.length) {
184
+ syncProps(propsStack, element);
185
+ } else {
186
+ ref.__propsStack = [];
187
+ element.props = {};
188
+ }
189
+ };
190
+ const initProps = function(element, parent, options) {
191
+ const { __ref: ref } = element;
192
+ if (ref.__if) applyProps(element, parent);
193
+ else {
194
+ try {
195
+ applyProps(element, parent);
196
+ } catch {
197
+ element.props = {};
198
+ ref.__propsStack = [];
199
+ }
200
+ }
201
+ setPropsPrototype(element);
202
+ return element;
203
+ };
204
+ const updateProps = (newProps, element, parent) => {
205
+ const { __ref: ref } = element;
206
+ const propsStack = ref.__propsStack || [];
207
+ let newStack = [...propsStack];
208
+ const parentProps = inheritParentProps(element, parent);
209
+ if (parentProps.length) {
210
+ newStack = [...parentProps, ...newStack];
211
+ }
212
+ if (newProps) {
213
+ newStack = [newProps, ...newStack];
214
+ }
215
+ ref.__propsStack = removeDuplicateProps(newStack);
216
+ if (ref.__propsStack.length) {
217
+ syncProps(ref.__propsStack, element);
218
+ }
219
+ return element;
220
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var scope_exports = {};
20
+ __export(scope_exports, {
21
+ createScope: () => createScope
22
+ });
23
+ module.exports = __toCommonJS(scope_exports);
24
+ const createScope = (element, parent) => {
25
+ var _a;
26
+ const { __ref: ref } = element;
27
+ if (!element.scope) element.scope = parent.scope || ((_a = ref.root) == null ? void 0 : _a.scope) || {};
28
+ };
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var state_exports = {};
20
+ __export(state_exports, {
21
+ applyDependentState: () => applyDependentState,
22
+ checkForStateTypes: () => checkForStateTypes,
23
+ checkIfInherits: () => checkIfInherits,
24
+ createInheritedState: () => createInheritedState,
25
+ createNestedObjectByKeyPath: () => createNestedObjectByKeyPath,
26
+ findInheritedState: () => findInheritedState,
27
+ getChildStateInKey: () => getChildStateInKey,
28
+ getParentStateInKey: () => getParentStateInKey,
29
+ getRootStateInKey: () => getRootStateInKey,
30
+ isState: () => isState,
31
+ overwriteState: () => overwriteState
32
+ });
33
+ module.exports = __toCommonJS(state_exports);
34
+ var import_array = require("./array.js");
35
+ var import_keys = require("./keys.js");
36
+ var import_object = require("./object.js");
37
+ var import_types = require("./types.js");
38
+ const checkForStateTypes = async (element) => {
39
+ const { state: orig, props, __ref: ref } = element;
40
+ const state = (props == null ? void 0 : props.state) || orig;
41
+ if ((0, import_types.isFunction)(state)) {
42
+ ref.__state = state;
43
+ return await (0, import_object.execPromise)(state, element);
44
+ } else if ((0, import_types.is)(state)("string", "number")) {
45
+ ref.__state = state;
46
+ return { value: state };
47
+ } else if (state === true) {
48
+ ref.__state = element.key;
49
+ return {};
50
+ } else if (state) {
51
+ ref.__hasRootState = true;
52
+ return state;
53
+ } else {
54
+ return false;
55
+ }
56
+ };
57
+ const getRootStateInKey = (stateKey, parentState) => {
58
+ if (!stateKey.includes("~/")) return;
59
+ const arr = stateKey.split("~/");
60
+ if (arr.length > 1) return parentState.root;
61
+ };
62
+ const getParentStateInKey = (stateKey, parentState) => {
63
+ if (!stateKey.includes("../")) return;
64
+ const arr = stateKey.split("../");
65
+ const arrLength = arr.length - 1;
66
+ for (let i = 0; i < arrLength; i++) {
67
+ if (!parentState.parent) return null;
68
+ parentState = parentState.parent;
69
+ }
70
+ return parentState;
71
+ };
72
+ const getChildStateInKey = (stateKey, parentState, options = {}) => {
73
+ const arr = (0, import_types.isString)(stateKey) ? stateKey.split("/") : [stateKey];
74
+ const arrLength = arr.length - 1;
75
+ for (let i = 0; i < arrLength; i++) {
76
+ const childKey = arr[i];
77
+ const grandChildKey = arr[i + 1];
78
+ if (childKey === "__proto__" || grandChildKey === "__proto__") return;
79
+ let childInParent = parentState[childKey];
80
+ if (!childInParent) childInParent = parentState[childKey] = {};
81
+ if (!childInParent[grandChildKey]) childInParent[grandChildKey] = {};
82
+ stateKey = grandChildKey;
83
+ parentState = childInParent;
84
+ }
85
+ if (options.returnParent) return parentState;
86
+ return parentState[stateKey];
87
+ };
88
+ const findInheritedState = (element, parent, options = {}) => {
89
+ const ref = element.__ref;
90
+ let stateKey = ref.__state;
91
+ if (!checkIfInherits(element)) return;
92
+ const rootState = getRootStateInKey(stateKey, parent.state);
93
+ let parentState = parent.state;
94
+ if (rootState) {
95
+ parentState = rootState;
96
+ stateKey = stateKey.replaceAll("~/", "");
97
+ } else {
98
+ const findGrandParentState = getParentStateInKey(stateKey, parent.state);
99
+ if (findGrandParentState) {
100
+ parentState = findGrandParentState;
101
+ stateKey = stateKey.replaceAll("../", "");
102
+ }
103
+ }
104
+ if (!parentState) return;
105
+ return getChildStateInKey(stateKey, parentState, options);
106
+ };
107
+ const createInheritedState = (element, parent) => {
108
+ const ref = element.__ref;
109
+ const inheritedState = findInheritedState(element, parent);
110
+ if ((0, import_types.isUndefined)(inheritedState)) return element.state;
111
+ if ((0, import_types.is)(inheritedState)("object", "array")) {
112
+ return (0, import_object.deepClone)(inheritedState);
113
+ } else if ((0, import_types.is)(inheritedState)("string", "number", "boolean")) {
114
+ ref.__stateType = typeof inheritedState;
115
+ return { value: inheritedState };
116
+ }
117
+ console.warn(ref.__state, "is not present. Replacing with", {});
118
+ };
119
+ const checkIfInherits = (element) => {
120
+ const { __ref: ref } = element;
121
+ const stateKey = ref == null ? void 0 : ref.__state;
122
+ if (stateKey && (0, import_types.is)(stateKey)("number", "string", "boolean")) return true;
123
+ return false;
124
+ };
125
+ const isState = function(state) {
126
+ if (!(0, import_types.isObjectLike)(state)) return false;
127
+ return Boolean(
128
+ state.update && state.parse && state.clean && state.create && state.parent && state.destroy && state.rootUpdate && state.parentUpdate && state.keys && state.values && state.toggle && state.replace && state.quietUpdate && state.quietReplace && state.add && state.apply && state.applyReplace && state.setByPath && state.setPathCollection && state.removeByPath && state.removePathCollection && state.getByPath && state.applyFunction && state.__element && state.__children
129
+ );
130
+ };
131
+ const createNestedObjectByKeyPath = (path, value) => {
132
+ if (!path) {
133
+ return value || {};
134
+ }
135
+ const keys = path.split("/");
136
+ const obj = {};
137
+ let ref = obj;
138
+ keys.forEach((key, index) => {
139
+ ref[key] = index === keys.length - 1 ? value || {} : {};
140
+ ref = ref[key];
141
+ });
142
+ return obj;
143
+ };
144
+ const applyDependentState = async (element, state) => {
145
+ const { __element } = state;
146
+ const origState = await (0, import_object.execPromise)(__element == null ? void 0 : __element.state, element);
147
+ if (!origState) return;
148
+ const dependentState = (0, import_object.deepClone)(origState, import_keys.STATE_METHODS);
149
+ const newDepends = { [element.key]: dependentState };
150
+ const __depends = (0, import_types.isObject)(origState.__depends) ? { ...origState.__depends, ...newDepends } : newDepends;
151
+ if (Array.isArray(origState)) {
152
+ (0, import_array.addProtoToArray)(origState, {
153
+ ...Object.getPrototypeOf(origState),
154
+ __depends
155
+ });
156
+ } else {
157
+ Object.setPrototypeOf(origState, {
158
+ ...Object.getPrototypeOf(origState),
159
+ __depends
160
+ });
161
+ }
162
+ return dependentState;
163
+ };
164
+ const overwriteState = (state, obj, options = {}) => {
165
+ const { overwrite } = options;
166
+ if (!overwrite) return;
167
+ const shallow = overwrite === "shallow";
168
+ const merge = overwrite === "merge";
169
+ if (merge) {
170
+ (0, import_object.deepMerge)(state, obj, import_keys.STATE_METHODS);
171
+ return;
172
+ }
173
+ const overwriteFunc = shallow ? import_object.overwriteShallow : import_object.overwriteDeep;
174
+ overwriteFunc(state, obj, import_keys.STATE_METHODS);
175
+ };
@@ -43,29 +43,37 @@ const trimStringFromSymbols = (str, characters) => {
43
43
  return str.replace(pattern, "");
44
44
  };
45
45
  const brackRegex = {
46
- 2: /\{\{\s*((?:\.\.\/)+)?([^}\s]+)\s*\}\}/g,
47
- 3: /\{\{\{\s*((?:\.\.\/)+)?([^}\s]+)\s*\}\}\}/g
46
+ 2: /{{\s*((?:\.\.\/)*)([\w\d.]+)\s*}}/g,
47
+ 3: /{{{(\s*(?:\.\.\/)*)([\w\d.]+)\s*}}}/g
48
48
  };
49
- function replaceLiteralsWithObjectFields(str, options = {}, forcedState) {
50
- if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{"))
51
- return str;
52
- const reg = brackRegex[options.bracketsLength || 2];
53
- const obj = forcedState || (this == null ? void 0 : this.state) || {};
49
+ const getNestedValue = (obj, path) => {
50
+ return path.split(".").reduce((acc, part) => {
51
+ return acc && acc[part] !== void 0 ? acc[part] : void 0;
52
+ }, obj);
53
+ };
54
+ function replaceLiteralsWithObjectFields(str, state = {}, options = {}) {
55
+ const { bracketsLength = 2 } = options;
56
+ const bracketPattern = bracketsLength === 3 ? "{{{" : "{{";
57
+ if (!str.includes(bracketPattern)) return str;
58
+ const reg = brackRegex[bracketsLength];
59
+ const obj = state || {};
54
60
  return str.replace(reg, (_, parentPath, variable) => {
55
61
  if (parentPath) {
56
- const parentLevels = parentPath.match(options.bracketsLength === 3 ? /\.\.\.\//g : /\.\.\//g).length;
62
+ const parentLevels = (parentPath.match(/\.\.\//g) || []).length;
57
63
  let parentState = obj;
58
64
  for (let i = 0; i < parentLevels; i++) {
65
+ if (!parentState || !parentState.parent) return "";
59
66
  parentState = parentState.parent;
60
- if (!parentState) {
61
- return "";
62
- }
63
67
  }
64
- const value = parentState[variable.trim()];
65
- return value !== void 0 ? `${value}` : "";
68
+ const key = variable.trim();
69
+ if (key === "parent") {
70
+ return parentState.value !== void 0 ? String(parentState.value) : "";
71
+ }
72
+ const value = getNestedValue(parentState, key);
73
+ return value !== void 0 ? String(value) : "";
66
74
  } else {
67
- const value = obj[variable.trim()];
68
- return value !== void 0 ? `${value}` : "";
75
+ const value = getNestedValue(obj, variable.trim());
76
+ return value !== void 0 ? String(value) : "";
69
77
  }
70
78
  });
71
79
  }
@@ -141,5 +149,8 @@ const customEncodeURIComponent = (str) => {
141
149
  }).join("");
142
150
  };
143
151
  const customDecodeURIComponent = (encodedStr) => {
144
- return encodedStr.replace(/%[0-9A-Fa-f]{2}/g, (match) => String.fromCharCode(parseInt(match.slice(1), 16)));
152
+ return encodedStr.replace(
153
+ /%[0-9A-Fa-f]{2}/g,
154
+ (match) => String.fromCharCode(parseInt(match.slice(1), 16))
155
+ );
145
156
  };
package/dist/cjs/types.js CHANGED
@@ -36,8 +36,7 @@ __export(types_exports, {
36
36
  module.exports = __toCommonJS(types_exports);
37
37
  var import_node = require("./node.js");
38
38
  const isObject = (arg) => {
39
- if (arg === null)
40
- return false;
39
+ if (arg === null) return false;
41
40
  return typeof arg === "object" && arg.constructor === Object;
42
41
  };
43
42
  const isString = (arg) => typeof arg === "string";
@@ -48,8 +47,7 @@ const isNull = (arg) => arg === null;
48
47
  const isArray = (arg) => Array.isArray(arg);
49
48
  const isDate = (d) => d instanceof Date;
50
49
  const isObjectLike = (arg) => {
51
- if (arg === null)
52
- return false;
50
+ if (arg === null) return false;
53
51
  return typeof arg === "object";
54
52
  };
55
53
  const isDefined = (arg) => {
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var update_exports = {};
20
+ __export(update_exports, {
21
+ captureSnapshot: () => captureSnapshot
22
+ });
23
+ module.exports = __toCommonJS(update_exports);
24
+ var import_key = require("./key.js");
25
+ const snapshot = {
26
+ snapshotId: import_key.createSnapshotId
27
+ };
28
+ const captureSnapshot = (element, options) => {
29
+ const ref = element.__ref;
30
+ const { currentSnapshot, calleeElement } = options;
31
+ const isCallee = calleeElement === element;
32
+ if (!calleeElement || isCallee) {
33
+ const createdStanpshot = snapshot.snapshotId();
34
+ ref.__currentSnapshot = createdStanpshot;
35
+ return [createdStanpshot, element];
36
+ }
37
+ const snapshotOnCallee = calleeElement.__ref.__currentSnapshot;
38
+ if (currentSnapshot < snapshotOnCallee) {
39
+ return [snapshotOnCallee, calleeElement, true];
40
+ }
41
+ return [snapshotOnCallee, calleeElement];
42
+ };
package/dist/esm/array.js CHANGED
@@ -9,31 +9,29 @@ const getFrequencyInArray = (arr, value) => {
9
9
  }, 0);
10
10
  };
11
11
  const removeFromArray = (arr, index) => {
12
- if (isString(index))
13
- index = parseInt(index);
12
+ if (isString(index)) index = parseInt(index);
14
13
  if (isNumber(index)) {
15
14
  if (index < 0 || index >= arr.length || isNaN(index)) {
16
15
  throw new Error("Invalid index");
17
16
  }
18
17
  arr.splice(index, 1);
19
- } else if (isArray(index)) {
20
- index.forEach((idx) => removeFromArray(arr, idx));
21
18
  } else {
22
19
  throw new Error("Invalid index");
23
20
  }
24
21
  return arr;
25
22
  };
26
23
  const swapItemsInArray = (arr, i, j) => {
24
+ ;
27
25
  [arr[i], arr[j]] = [arr[j], arr[i]];
28
26
  };
29
27
  const joinArrays = (...arrays) => {
30
28
  return [].concat(...arrays);
31
29
  };
32
- const mergeArray = (arr, exclude = []) => {
33
- return arr.reduce((a, c) => deepMerge(a, deepClone(c, { exclude }), exclude), {});
34
- };
35
- const mergeAndCloneIfArray = (obj) => {
36
- return isArray(obj) ? mergeArray(obj) : deepClone(obj);
30
+ const unstackArrayOfObjects = (arr, exclude = []) => {
31
+ return arr.reduce(
32
+ (a, c) => deepMerge(a, deepClone(c, { exclude }), exclude),
33
+ {}
34
+ );
37
35
  };
38
36
  const cutArrayBeforeValue = (arr, value) => {
39
37
  const index = arr.indexOf(value);
@@ -43,8 +41,7 @@ const cutArrayBeforeValue = (arr, value) => {
43
41
  return arr;
44
42
  };
45
43
  const cutArrayAfterValue = (arr, value) => {
46
- if (!isArray(arr))
47
- return;
44
+ if (!isArray(arr)) return;
48
45
  const index = arr.indexOf(value);
49
46
  if (index !== -1) {
50
47
  return arr.slice(index + 1);
@@ -103,12 +100,29 @@ const filterArraysFast = (sourceArr, excludeArr) => {
103
100
  return sourceArr.filter((item) => !excludeSet.has(item));
104
101
  };
105
102
  const checkIfStringIsInArray = (string, arr) => {
106
- if (!string)
107
- return;
103
+ if (!string) return;
108
104
  return arr.filter((v) => string.includes(v)).length;
109
105
  };
106
+ const removeDuplicatesInArray = (arr) => {
107
+ if (!isArray(arr)) return arr;
108
+ return [...new Set(arr)];
109
+ };
110
+ const addProtoToArray = (state, proto) => {
111
+ for (const key in proto) {
112
+ Object.defineProperty(state, key, {
113
+ value: proto[key],
114
+ enumerable: false,
115
+ // Set this to true if you want the method to appear in for...in loops
116
+ configurable: true,
117
+ // Set this to true if you want to allow redefining/removing the property later
118
+ writable: true
119
+ // Set this to true if you want to allow changing the function later
120
+ });
121
+ }
122
+ };
110
123
  export {
111
124
  addItemAfterEveryElement,
125
+ addProtoToArray,
112
126
  arrayContainsOtherArray,
113
127
  arraysEqual,
114
128
  checkIfStringIsInArray,
@@ -118,11 +132,11 @@ export {
118
132
  filterArraysFast,
119
133
  getFrequencyInArray,
120
134
  joinArrays,
121
- mergeAndCloneIfArray,
122
- mergeArray,
135
+ removeDuplicatesInArray,
123
136
  removeFromArray,
124
137
  removeValueFromArray,
125
138
  removeValueFromArrayAll,
126
139
  reorderArrayByValues,
127
- swapItemsInArray
140
+ swapItemsInArray,
141
+ unstackArrayOfObjects
128
142
  };
@@ -0,0 +1,6 @@
1
+ const cache = {};
2
+ const OPTIONS = {};
3
+ export {
4
+ OPTIONS,
5
+ cache
6
+ };