@domql/utils 2.5.178 → 2.5.184

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.
package/array.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
- import { deepClone, deepMerge } from './object'
4
- import { isArray, isNumber, isString } from './types'
3
+ import { deepClone, deepMerge } from './object.js'
4
+ import { isArray, isNumber, isString } from './types.js'
5
5
 
6
6
  export const arrayContainsOtherArray = (arr1, arr2) => {
7
7
  return arr2.every(val => arr1.includes(val))
package/component.js CHANGED
@@ -1,14 +1,9 @@
1
1
  'use strict'
2
2
 
3
- import {
4
- deepClone,
5
- exec,
6
- isArray,
7
- isFunction,
8
- isObject,
9
- isString,
10
- joinArrays
11
- } from '.'
3
+ import { joinArrays } from './array.js'
4
+ import { deepClone, exec } from './object.js'
5
+ import { isArray, isFunction, isObject, isString } from './types.js'
6
+
12
7
  const ENV = process.env.NODE_ENV
13
8
 
14
9
  export const checkIfKeyIsComponent = (key) => {
package/cookie.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
- import { isUndefined } from './types'
4
- import { document } from '@domql/utils'
3
+ import { isUndefined } from './types.js'
4
+ import { document } from './globals.js'
5
5
 
6
6
  export const isMobile = (() => typeof navigator === 'undefined'
7
7
  ? false
package/dist/cjs/array.js CHANGED
@@ -37,8 +37,8 @@ __export(array_exports, {
37
37
  swapItemsInArray: () => swapItemsInArray
38
38
  });
39
39
  module.exports = __toCommonJS(array_exports);
40
- var import_object = require("./object");
41
- var import_types = require("./types");
40
+ var import_object = require("./object.js");
41
+ var import_types = require("./types.js");
42
42
  const arrayContainsOtherArray = (arr1, arr2) => {
43
43
  return arr2.every((val) => arr1.includes(val));
44
44
  };
@@ -35,17 +35,19 @@ __export(component_exports, {
35
35
  setContentKey: () => setContentKey
36
36
  });
37
37
  module.exports = __toCommonJS(component_exports);
38
- var import__ = require(".");
38
+ var import_array = require("./array.js");
39
+ var import_object = require("./object.js");
40
+ var import_types = require("./types.js");
39
41
  const ENV = "development";
40
42
  const checkIfKeyIsComponent = (key) => {
41
- const isFirstKeyString = (0, import__.isString)(key);
43
+ const isFirstKeyString = (0, import_types.isString)(key);
42
44
  if (!isFirstKeyString)
43
45
  return;
44
46
  const firstCharKey = key.slice(0, 1);
45
47
  return /^[A-Z]*$/.test(firstCharKey);
46
48
  };
47
49
  const checkIfKeyIsProperty = (key) => {
48
- const isFirstKeyString = (0, import__.isString)(key);
50
+ const isFirstKeyString = (0, import_types.isString)(key);
49
51
  if (!isFirstKeyString)
50
52
  return;
51
53
  const firstCharKey = key.slice(0, 1);
@@ -55,9 +57,9 @@ const addAdditionalExtend = (newExtend, element) => {
55
57
  if (!newExtend)
56
58
  return element;
57
59
  const { extend: elementExtend } = element;
58
- const originalArray = (0, import__.isArray)(elementExtend) ? elementExtend : [elementExtend];
59
- const receivedArray = (0, import__.isArray)(newExtend) ? newExtend : [newExtend];
60
- const extend = (0, import__.joinArrays)(receivedArray, originalArray);
60
+ const originalArray = (0, import_types.isArray)(elementExtend) ? elementExtend : [elementExtend];
61
+ const receivedArray = (0, import_types.isArray)(newExtend) ? newExtend : [newExtend];
62
+ const extend = (0, import_array.joinArrays)(receivedArray, originalArray);
61
63
  return { ...element, extend };
62
64
  };
63
65
  const checkIfSugar = (element, parent, key) => {
@@ -127,11 +129,11 @@ const extendizeByKey = (element, parent, key) => {
127
129
  };
128
130
  } else if (extend) {
129
131
  return addAdditionalExtend(extendFromKey, element);
130
- } else if ((0, import__.isFunction)(element)) {
132
+ } else if ((0, import_types.isFunction)(element)) {
131
133
  return {
132
134
  extend: extendFromKey,
133
135
  tag,
134
- props: { ...(0, import__.exec)(element, parent) }
136
+ props: { ...(0, import_object.exec)(element, parent) }
135
137
  };
136
138
  }
137
139
  };
@@ -155,7 +157,7 @@ const addChildrenIfNotInOriginal = (element, parent, key) => {
155
157
  if (newChild === null)
156
158
  assignChild(null);
157
159
  else if (!childElem)
158
- assignChild((0, import__.deepClone)(newChild));
160
+ assignChild((0, import_object.deepClone)(newChild));
159
161
  else {
160
162
  const isSugarChildElem = checkIfSugar(childElem, parent, key);
161
163
  if (isSugarChildElem)
@@ -176,8 +178,8 @@ const applyComponentFromContext = (element, parent, options) => {
176
178
  return;
177
179
  const { components } = context;
178
180
  const { extend } = element;
179
- const execExtend = (0, import__.exec)(extend, element);
180
- if ((0, import__.isString)(execExtend)) {
181
+ const execExtend = (0, import_object.exec)(extend, element);
182
+ if ((0, import_types.isString)(execExtend)) {
181
183
  const componentExists = components[execExtend] || components["smbls." + execExtend];
182
184
  if (componentExists)
183
185
  element.extend = componentExists;
@@ -191,14 +193,14 @@ const applyComponentFromContext = (element, parent, options) => {
191
193
  }
192
194
  };
193
195
  const isVariant = (param) => {
194
- if (!(0, import__.isString)(param))
196
+ if (!(0, import_types.isString)(param))
195
197
  return;
196
198
  const firstCharKey = param.slice(0, 1);
197
199
  return firstCharKey === ".";
198
200
  };
199
201
  const hasVariantProp = (element) => {
200
202
  const { props } = element;
201
- if ((0, import__.isObject)(props) && (0, import__.isString)(props.variant))
203
+ if ((0, import_types.isObject)(props) && (0, import_types.isString)(props.variant))
202
204
  return true;
203
205
  };
204
206
  const getChildrenComponentsByKey = (key, el) => {
@@ -206,14 +208,14 @@ const getChildrenComponentsByKey = (key, el) => {
206
208
  return el;
207
209
  }
208
210
  if (el.extend) {
209
- const foundString = (0, import__.isString)(el.extend) && el.extend === key;
210
- const foundInArray = (0, import__.isArray)(el.extend) && el.extend.filter((v) => v === key).length;
211
+ const foundString = (0, import_types.isString)(el.extend) && el.extend === key;
212
+ const foundInArray = (0, import_types.isArray)(el.extend) && el.extend.filter((v) => v === key).length;
211
213
  if (foundString || foundInArray)
212
214
  return el;
213
215
  }
214
216
  if (el.parent && el.parent.childExtend) {
215
- const foundString = (0, import__.isString)(el.parent.childExtend) && el.parent.childExtend === key;
216
- const foundInArray = (0, import__.isArray)(el.parent.childExtend) && el.parent.childExtend.filter((v) => v === key).length;
217
+ const foundString = (0, import_types.isString)(el.parent.childExtend) && el.parent.childExtend === key;
218
+ const foundInArray = (0, import_types.isArray)(el.parent.childExtend) && el.parent.childExtend.filter((v) => v === key).length;
217
219
  if (foundString || foundInArray)
218
220
  return el;
219
221
  }
@@ -26,22 +26,22 @@ __export(cookie_exports, {
26
26
  setLocalStorage: () => setLocalStorage
27
27
  });
28
28
  module.exports = __toCommonJS(cookie_exports);
29
- var import_types = require("./types");
30
- var import_utils = require("@domql/utils");
29
+ var import_types = require("./types.js");
30
+ var import_globals = require("./globals.js");
31
31
  const isMobile = (() => typeof navigator === "undefined" ? false : /Mobi/.test(navigator.userAgent))();
32
32
  const setCookie = (cname, cvalue, exdays = 365) => {
33
- if ((0, import_types.isUndefined)(import_utils.document) || (0, import_types.isUndefined)(import_utils.document.cookie))
33
+ if ((0, import_types.isUndefined)(import_globals.document) || (0, import_types.isUndefined)(import_globals.document.cookie))
34
34
  return;
35
35
  const d = /* @__PURE__ */ new Date();
36
36
  d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1e3);
37
37
  const expires = `expires=${d.toUTCString()}`;
38
- import_utils.document.cookie = `${cname}=${cvalue};${expires};path=/`;
38
+ import_globals.document.cookie = `${cname}=${cvalue};${expires};path=/`;
39
39
  };
40
40
  const getCookie = (cname) => {
41
- if ((0, import_types.isUndefined)(import_utils.document) || (0, import_types.isUndefined)(import_utils.document.cookie))
41
+ if ((0, import_types.isUndefined)(import_globals.document) || (0, import_types.isUndefined)(import_globals.document.cookie))
42
42
  return;
43
43
  const name = `${cname}=`;
44
- const decodedCookie = decodeURIComponent(import_utils.document.cookie);
44
+ const decodedCookie = decodeURIComponent(import_globals.document.cookie);
45
45
  const ca = decodedCookie.split(";");
46
46
  for (let i = 0; i < ca.length; i++) {
47
47
  let c = ca[i];
@@ -53,9 +53,9 @@ const getCookie = (cname) => {
53
53
  return "";
54
54
  };
55
55
  const removeCookie = (cname) => {
56
- if ((0, import_types.isUndefined)(import_utils.document) || (0, import_types.isUndefined)(import_utils.document.cookie))
56
+ if ((0, import_types.isUndefined)(import_globals.document) || (0, import_types.isUndefined)(import_globals.document.cookie))
57
57
  return;
58
- import_utils.document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
58
+ import_globals.document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
59
59
  };
60
60
  function getLocalStorage(key) {
61
61
  let savedJSON;
package/dist/cjs/node.js CHANGED
@@ -23,7 +23,7 @@ __export(node_exports, {
23
23
  isNode: () => isNode
24
24
  });
25
25
  module.exports = __toCommonJS(node_exports);
26
- var import_globals = require("./globals");
26
+ var import_globals = require("./globals.js");
27
27
  const isNode = (obj) => {
28
28
  return (typeof Node === "object" ? obj instanceof import_globals.window.Node : obj && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string") || false;
29
29
  };
@@ -36,6 +36,7 @@ __export(object_exports, {
36
36
  excludeKeysFromObject: () => excludeKeysFromObject,
37
37
  exec: () => exec,
38
38
  flattenRecursive: () => flattenRecursive,
39
+ getInObjectByPath: () => getInObjectByPath,
39
40
  hasOwnProperty: () => hasOwnProperty,
40
41
  isCyclic: () => isCyclic,
41
42
  isEmpty: () => isEmpty,
@@ -52,6 +53,7 @@ __export(object_exports, {
52
53
  overwriteShallow: () => overwriteShallow,
53
54
  removeFromObject: () => removeFromObject,
54
55
  removeNestedKeyByPath: () => removeNestedKeyByPath,
56
+ setInObjectByPath: () => setInObjectByPath,
55
57
  stringToObject: () => stringToObject
56
58
  });
57
59
  module.exports = __toCommonJS(object_exports);
@@ -614,6 +616,34 @@ const removeNestedKeyByPath = (obj, path) => {
614
616
  delete current[lastKey];
615
617
  }
616
618
  };
619
+ const setInObjectByPath = (obj, path, value) => {
620
+ if (!Array.isArray(path)) {
621
+ throw new Error("Path must be an array.");
622
+ }
623
+ let current = obj;
624
+ for (let i = 0; i < path.length - 1; i++) {
625
+ if (!current[path[i]] || typeof current[path[i]] !== "object") {
626
+ current[path[i]] = {};
627
+ }
628
+ current = current[path[i]];
629
+ }
630
+ const lastKey = path[path.length - 1];
631
+ current[lastKey] = value;
632
+ return obj;
633
+ };
634
+ const getInObjectByPath = (obj, path) => {
635
+ if (!Array.isArray(path)) {
636
+ throw new Error("Path must be an array.");
637
+ }
638
+ let current = obj;
639
+ for (let i = 0; i < path.length; i++) {
640
+ if (current === void 0 || current === null) {
641
+ return void 0;
642
+ }
643
+ current = current[path[i]];
644
+ }
645
+ return current;
646
+ };
617
647
  const detectInfiniteLoop = (arr) => {
618
648
  const maxRepeats = 10;
619
649
  let pattern = [];
@@ -50,7 +50,7 @@ function replaceLiteralsWithObjectFields(str, options = {}, forcedState) {
50
50
  if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{"))
51
51
  return str;
52
52
  const reg = brackRegex[options.bracketsLength || 2];
53
- const obj = forcedState || this.state || {};
53
+ const obj = forcedState || (this == null ? void 0 : this.state) || {};
54
54
  return str.replace(reg, (_, parentPath, variable) => {
55
55
  if (parentPath) {
56
56
  const parentLevels = parentPath.match(options.bracketsLength === 3 ? /\.\.\.\//g : /\.\.\//g).length;
package/dist/cjs/types.js CHANGED
@@ -34,7 +34,7 @@ __export(types_exports, {
34
34
  isUndefined: () => isUndefined
35
35
  });
36
36
  module.exports = __toCommonJS(types_exports);
37
- var import_node = require("./node");
37
+ var import_node = require("./node.js");
38
38
  const isObject = (arg) => {
39
39
  if (arg === null)
40
40
  return false;
package/dist/esm/array.js CHANGED
@@ -1,5 +1,5 @@
1
- import { deepClone, deepMerge } from "./object";
2
- import { isArray, isNumber, isString } from "./types";
1
+ import { deepClone, deepMerge } from "./object.js";
2
+ import { isArray, isNumber, isString } from "./types.js";
3
3
  const arrayContainsOtherArray = (arr1, arr2) => {
4
4
  return arr2.every((val) => arr1.includes(val));
5
5
  };
@@ -17,15 +17,9 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- import {
21
- deepClone,
22
- exec,
23
- isArray,
24
- isFunction,
25
- isObject,
26
- isString,
27
- joinArrays
28
- } from ".";
20
+ import { joinArrays } from "./array.js";
21
+ import { deepClone, exec } from "./object.js";
22
+ import { isArray, isFunction, isObject, isString } from "./types.js";
29
23
  const ENV = "development";
30
24
  const checkIfKeyIsComponent = (key) => {
31
25
  const isFirstKeyString = isString(key);
@@ -1,5 +1,5 @@
1
- import { isUndefined } from "./types";
2
- import { document } from "@domql/utils";
1
+ import { isUndefined } from "./types.js";
2
+ import { document } from "./globals.js";
3
3
  const isMobile = (() => typeof navigator === "undefined" ? false : /Mobi/.test(navigator.userAgent))();
4
4
  const setCookie = (cname, cvalue, exdays = 365) => {
5
5
  if (isUndefined(document) || isUndefined(document.cookie))
package/dist/esm/node.js CHANGED
@@ -1,4 +1,4 @@
1
- import { window } from "./globals";
1
+ import { window } from "./globals.js";
2
2
  const isNode = (obj) => {
3
3
  return (typeof Node === "object" ? obj instanceof window.Node : obj && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string") || false;
4
4
  };
@@ -585,6 +585,34 @@ const removeNestedKeyByPath = (obj, path) => {
585
585
  delete current[lastKey];
586
586
  }
587
587
  };
588
+ const setInObjectByPath = (obj, path, value) => {
589
+ if (!Array.isArray(path)) {
590
+ throw new Error("Path must be an array.");
591
+ }
592
+ let current = obj;
593
+ for (let i = 0; i < path.length - 1; i++) {
594
+ if (!current[path[i]] || typeof current[path[i]] !== "object") {
595
+ current[path[i]] = {};
596
+ }
597
+ current = current[path[i]];
598
+ }
599
+ const lastKey = path[path.length - 1];
600
+ current[lastKey] = value;
601
+ return obj;
602
+ };
603
+ const getInObjectByPath = (obj, path) => {
604
+ if (!Array.isArray(path)) {
605
+ throw new Error("Path must be an array.");
606
+ }
607
+ let current = obj;
608
+ for (let i = 0; i < path.length; i++) {
609
+ if (current === void 0 || current === null) {
610
+ return void 0;
611
+ }
612
+ current = current[path[i]];
613
+ }
614
+ return current;
615
+ };
588
616
  const detectInfiniteLoop = (arr) => {
589
617
  const maxRepeats = 10;
590
618
  let pattern = [];
@@ -651,6 +679,7 @@ export {
651
679
  excludeKeysFromObject,
652
680
  exec,
653
681
  flattenRecursive,
682
+ getInObjectByPath,
654
683
  hasOwnProperty,
655
684
  isCyclic,
656
685
  isEmpty,
@@ -667,5 +696,6 @@ export {
667
696
  overwriteShallow,
668
697
  removeFromObject,
669
698
  removeNestedKeyByPath,
699
+ setInObjectByPath,
670
700
  stringToObject
671
701
  };
@@ -18,7 +18,7 @@ function replaceLiteralsWithObjectFields(str, options = {}, forcedState) {
18
18
  if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{"))
19
19
  return str;
20
20
  const reg = brackRegex[options.bracketsLength || 2];
21
- const obj = forcedState || this.state || {};
21
+ const obj = forcedState || (this == null ? void 0 : this.state) || {};
22
22
  return str.replace(reg, (_, parentPath, variable) => {
23
23
  if (parentPath) {
24
24
  const parentLevels = parentPath.match(options.bracketsLength === 3 ? /\.\.\.\//g : /\.\.\//g).length;
package/dist/esm/types.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isHtmlElement, isNode } from "./node";
1
+ import { isHtmlElement, isNode } from "./node.js";
2
2
  const isObject = (arg) => {
3
3
  if (arg === null)
4
4
  return false;
package/node.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { window } from './globals'
3
+ import { window } from './globals.js'
4
4
 
5
5
  export const isNode = (obj) => {
6
6
  return (
package/object.js CHANGED
@@ -737,6 +737,44 @@ export const removeNestedKeyByPath = (obj, path) => {
737
737
  }
738
738
  }
739
739
 
740
+ export const setInObjectByPath = (obj, path, value) => {
741
+ if (!Array.isArray(path)) {
742
+ throw new Error('Path must be an array.')
743
+ }
744
+
745
+ let current = obj
746
+
747
+ for (let i = 0; i < path.length - 1; i++) {
748
+ // If the current path segment doesn't exist or isn't an object, create it
749
+ if (!current[path[i]] || typeof current[path[i]] !== 'object') {
750
+ current[path[i]] = {}
751
+ }
752
+ current = current[path[i]]
753
+ }
754
+
755
+ const lastKey = path[path.length - 1]
756
+ current[lastKey] = value
757
+
758
+ return obj
759
+ }
760
+
761
+ export const getInObjectByPath = (obj, path) => {
762
+ if (!Array.isArray(path)) {
763
+ throw new Error('Path must be an array.')
764
+ }
765
+
766
+ let current = obj
767
+
768
+ for (let i = 0; i < path.length; i++) {
769
+ if (current === undefined || current === null) {
770
+ return undefined
771
+ }
772
+ current = current[path[i]]
773
+ }
774
+
775
+ return current
776
+ }
777
+
740
778
  export const detectInfiniteLoop = arr => {
741
779
  const maxRepeats = 10 // Maximum allowed repetitions
742
780
  let pattern = []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.5.178",
3
+ "version": "2.5.184",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -8,7 +8,7 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "kalduna": "./dist/esm/index.js",
11
- "default": "./dist/cjs/index.js",
11
+ "default": "./dist/esm/index.js",
12
12
  "import": "./dist/esm/index.js",
13
13
  "require": "./dist/cjs/index.js"
14
14
  }
@@ -25,7 +25,7 @@
25
25
  "build": "npm run build:cjs; npm run build:esm",
26
26
  "prepublish": "rimraf -I dist; npm run build; npm run copy:package:cjs"
27
27
  },
28
- "gitHead": "b274eb76e068d125b38f9e617fcfb98d657eafbd",
28
+ "gitHead": "d8fb0c7460a5bed587290d7c88c0f4ca291794e8",
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.12.0"
31
31
  }
package/string.js CHANGED
@@ -32,7 +32,7 @@ const brackRegex = {
32
32
  export function replaceLiteralsWithObjectFields (str, options = {}, forcedState) {
33
33
  if (!str.includes(options.bracketsLength === 3 ? '{{{' : '{{')) return str
34
34
  const reg = brackRegex[options.bracketsLength || 2]
35
- const obj = forcedState || this.state || {}
35
+ const obj = forcedState || this?.state || {}
36
36
  return str.replace(reg, (_, parentPath, variable) => {
37
37
  if (parentPath) {
38
38
  const parentLevels = parentPath.match(options.bracketsLength === 3 ? /\.\.\.\//g : /\.\.\//g).length
package/types.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { isHtmlElement, isNode } from './node'
3
+ import { isHtmlElement, isNode } from './node.js'
4
4
 
5
5
  export const isObject = arg => {
6
6
  if (arg === null) return false