@symbo.ls/utils 2.11.470 → 2.11.475

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/dist/cjs/index.js CHANGED
@@ -346,11 +346,11 @@ var require_array = __commonJS({
346
346
  var joinArrays = (...arrays) => {
347
347
  return [].concat(...arrays);
348
348
  };
349
- var mergeArray = (arr, excludeFrom = []) => {
350
- return arr.reduce((a, c) => (0, import_object.deepMerge)(a, (0, import_object.deepCloneWithExtend)(c, excludeFrom), excludeFrom), {});
349
+ var mergeArray = (arr, exclude = []) => {
350
+ return arr.reduce((a, c) => (0, import_object.deepMerge)(a, (0, import_object.deepClone)(c, { exclude }), exclude), {});
351
351
  };
352
352
  var mergeAndCloneIfArray = (obj) => {
353
- return (0, import_types.isArray)(obj) ? mergeArray(obj) : (0, import_object.deepCloneWithExtend)(obj);
353
+ return (0, import_types.isArray)(obj) ? mergeArray(obj) : (0, import_object.deepClone)(obj);
354
354
  };
355
355
  var cutArrayBeforeValue = (arr, value) => {
356
356
  const index = arr.indexOf(value);
@@ -599,8 +599,6 @@ var require_object = __commonJS({
599
599
  createNestedObject: () => createNestedObject,
600
600
  createObjectWithoutPrototype: () => createObjectWithoutPrototype,
601
601
  deepClone: () => deepClone,
602
- deepCloneExclude: () => deepCloneExclude,
603
- deepCloneWithExtend: () => deepCloneWithExtend,
604
602
  deepContains: () => deepContains,
605
603
  deepDestringify: () => deepDestringify,
606
604
  deepDiff: () => deepDiff,
@@ -694,78 +692,56 @@ var require_object = __commonJS({
694
692
  }
695
693
  return o;
696
694
  };
697
- var deepCloneExclude = (obj, excludeFrom = []) => {
698
- if ((0, import_types.isArray)(obj)) {
699
- return obj.map((x) => deepCloneExclude(x, excludeFrom));
700
- }
701
- const o = {};
702
- for (const k in obj) {
703
- const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, k);
704
- if (!hasOwnProperty2 || excludeFrom.includes(k) || k.startsWith("__"))
705
- continue;
706
- let v = obj[k];
707
- if (k === "extend" && (0, import_types.isArray)(v)) {
708
- v = mergeArrayExclude(v, excludeFrom);
709
- }
710
- if ((0, import_types.isArray)(v)) {
711
- o[k] = v.map((x) => deepCloneExclude(x, excludeFrom));
712
- } else if ((0, import_types.isObject)(v)) {
713
- o[k] = deepCloneExclude(v, excludeFrom);
714
- } else
715
- o[k] = v;
716
- }
717
- return o;
718
- };
719
- var mergeArrayExclude = (arr, excl = []) => {
720
- return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
695
+ var mergeArrayExclude = (arr, exclude = []) => {
696
+ return arr.reduce((acc, curr) => deepMerge(acc, deepClone(curr, { exclude })), {});
721
697
  };
722
- var deepClone = (obj, exclude = [], cleanUndefined = false, visited = /* @__PURE__ */ new WeakMap()) => {
723
- if (!(0, import_types.isObjectLike)(obj) || (0, import_node.isDOMNode)(obj))
698
+ var deepClone = (obj, options = {}) => {
699
+ const {
700
+ exclude = [],
701
+ cleanUndefined = false,
702
+ cleanNull = false,
703
+ window: targetWindow,
704
+ visited = /* @__PURE__ */ new WeakMap(),
705
+ handleExtend = false
706
+ } = options;
707
+ if (!(0, import_types.isObjectLike)(obj) || (0, import_node.isDOMNode)(obj)) {
724
708
  return obj;
725
- if (visited.has(obj))
709
+ }
710
+ if (visited.has(obj)) {
726
711
  return visited.get(obj);
727
- const clone2 = (0, import_types.isArray)(obj) ? [] : {};
712
+ }
713
+ const clone2 = targetWindow ? (0, import_types.isArray)(obj) ? new targetWindow.Array() : new targetWindow.Object() : (0, import_types.isArray)(obj) ? [] : {};
728
714
  visited.set(obj, clone2);
729
715
  for (const key in obj) {
730
- if (Object.prototype.hasOwnProperty.call(obj, key) && !exclude.includes(key)) {
731
- const value = obj[key];
732
- if ((0, import_node.isDOMNode)(value)) {
733
- clone2[key] = value;
734
- } else if (key === "extend" && (0, import_types.isArray)(value)) {
735
- clone2[key] = (0, import_array.mergeArray)(value, exclude);
736
- } else if ((0, import_types.isObjectLike)(value)) {
737
- clone2[key] = deepClone(value, exclude, cleanUndefined, visited);
738
- } else {
739
- clone2[key] = value;
740
- }
741
- }
742
- }
743
- return clone2;
744
- };
745
- var deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}, visited = /* @__PURE__ */ new WeakSet()) => {
746
- if ((0, import_types.isObjectLike)(obj)) {
747
- if (visited.has(obj)) {
748
- return obj;
716
+ if (!Object.prototype.hasOwnProperty.call(obj, key))
717
+ continue;
718
+ if (exclude.includes(key) || key.startsWith("__") || key === "__proto__")
719
+ continue;
720
+ const value = obj[key];
721
+ if (cleanUndefined && (0, import_types.isUndefined)(value) || cleanNull && (0, import_types.isNull)(value))
722
+ continue;
723
+ if ((0, import_node.isDOMNode)(value)) {
724
+ clone2[key] = value;
725
+ continue;
749
726
  }
750
- visited.add(obj);
751
- }
752
- const o = options.window ? (0, import_types.isArray)(obj) ? new options.window.Array([]) : new options.window.Object({}) : (0, import_types.isArray)(obj) ? [] : {};
753
- for (const prop in obj) {
754
- if (!Object.prototype.hasOwnProperty.call(obj, prop))
727
+ if (handleExtend && key === "extend" && (0, import_types.isArray)(value)) {
728
+ clone2[key] = (0, import_array.mergeArray)(value, exclude);
755
729
  continue;
756
- const objProp = obj[prop];
757
- if (excludeFrom.includes(prop) || prop.startsWith("__") || options.cleanUndefined && (0, import_types.isUndefined)(objProp) || options.cleanNull && (0, import_types.isNull)(objProp)) {
730
+ }
731
+ if ((0, import_types.isFunction)(value) && targetWindow) {
732
+ clone2[key] = targetWindow.eval("(" + value.toString() + ")");
758
733
  continue;
759
734
  }
760
- if ((0, import_types.isObjectLike)(objProp)) {
761
- o[prop] = deepCloneWithExtend(objProp, excludeFrom, options, visited);
762
- } else if ((0, import_types.isFunction)(objProp) && options.window) {
763
- o[prop] = (options.window || import_globals.window).eval("(" + objProp.toString() + ")");
735
+ if ((0, import_types.isObjectLike)(value)) {
736
+ clone2[key] = deepClone(value, {
737
+ ...options,
738
+ visited
739
+ });
764
740
  } else {
765
- o[prop] = objProp;
741
+ clone2[key] = value;
766
742
  }
767
743
  }
768
- return o;
744
+ return clone2;
769
745
  };
770
746
  var deepStringify = (obj, stringified = {}) => {
771
747
  var _a, _b;
@@ -1784,7 +1760,7 @@ var require_component = __commonJS({
1784
1760
  if (newChild === null)
1785
1761
  assignChild(null);
1786
1762
  else if (!childElem)
1787
- assignChild((0, import__.deepCloneWithExtend)(newChild));
1763
+ assignChild((0, import__.deepClone)(newChild));
1788
1764
  else {
1789
1765
  const isSugarChildElem = checkIfSugar(childElem, parent, key);
1790
1766
  if (isSugarChildElem)
@@ -346,11 +346,11 @@ var require_array = __commonJS({
346
346
  var joinArrays = (...arrays) => {
347
347
  return [].concat(...arrays);
348
348
  };
349
- var mergeArray = (arr, excludeFrom = []) => {
350
- return arr.reduce((a, c) => (0, import_object.deepMerge)(a, (0, import_object.deepCloneWithExtend)(c, excludeFrom), excludeFrom), {});
349
+ var mergeArray = (arr, exclude = []) => {
350
+ return arr.reduce((a, c) => (0, import_object.deepMerge)(a, (0, import_object.deepClone)(c, { exclude }), exclude), {});
351
351
  };
352
352
  var mergeAndCloneIfArray = (obj) => {
353
- return (0, import_types.isArray)(obj) ? mergeArray(obj) : (0, import_object.deepCloneWithExtend)(obj);
353
+ return (0, import_types.isArray)(obj) ? mergeArray(obj) : (0, import_object.deepClone)(obj);
354
354
  };
355
355
  var cutArrayBeforeValue = (arr, value) => {
356
356
  const index = arr.indexOf(value);
@@ -599,8 +599,6 @@ var require_object = __commonJS({
599
599
  createNestedObject: () => createNestedObject,
600
600
  createObjectWithoutPrototype: () => createObjectWithoutPrototype,
601
601
  deepClone: () => deepClone,
602
- deepCloneExclude: () => deepCloneExclude,
603
- deepCloneWithExtend: () => deepCloneWithExtend,
604
602
  deepContains: () => deepContains,
605
603
  deepDestringify: () => deepDestringify,
606
604
  deepDiff: () => deepDiff,
@@ -694,78 +692,56 @@ var require_object = __commonJS({
694
692
  }
695
693
  return o;
696
694
  };
697
- var deepCloneExclude = (obj, excludeFrom = []) => {
698
- if ((0, import_types.isArray)(obj)) {
699
- return obj.map((x) => deepCloneExclude(x, excludeFrom));
700
- }
701
- const o = {};
702
- for (const k in obj) {
703
- const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, k);
704
- if (!hasOwnProperty2 || excludeFrom.includes(k) || k.startsWith("__"))
705
- continue;
706
- let v = obj[k];
707
- if (k === "extend" && (0, import_types.isArray)(v)) {
708
- v = mergeArrayExclude(v, excludeFrom);
709
- }
710
- if ((0, import_types.isArray)(v)) {
711
- o[k] = v.map((x) => deepCloneExclude(x, excludeFrom));
712
- } else if ((0, import_types.isObject)(v)) {
713
- o[k] = deepCloneExclude(v, excludeFrom);
714
- } else
715
- o[k] = v;
716
- }
717
- return o;
718
- };
719
- var mergeArrayExclude = (arr, excl = []) => {
720
- return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
695
+ var mergeArrayExclude = (arr, exclude = []) => {
696
+ return arr.reduce((acc, curr) => deepMerge(acc, deepClone(curr, { exclude })), {});
721
697
  };
722
- var deepClone = (obj, exclude = [], cleanUndefined = false, visited = /* @__PURE__ */ new WeakMap()) => {
723
- if (!(0, import_types.isObjectLike)(obj) || (0, import_node.isDOMNode)(obj))
698
+ var deepClone = (obj, options = {}) => {
699
+ const {
700
+ exclude = [],
701
+ cleanUndefined = false,
702
+ cleanNull = false,
703
+ window: targetWindow,
704
+ visited = /* @__PURE__ */ new WeakMap(),
705
+ handleExtend = false
706
+ } = options;
707
+ if (!(0, import_types.isObjectLike)(obj) || (0, import_node.isDOMNode)(obj)) {
724
708
  return obj;
725
- if (visited.has(obj))
709
+ }
710
+ if (visited.has(obj)) {
726
711
  return visited.get(obj);
727
- const clone2 = (0, import_types.isArray)(obj) ? [] : {};
712
+ }
713
+ const clone2 = targetWindow ? (0, import_types.isArray)(obj) ? new targetWindow.Array() : new targetWindow.Object() : (0, import_types.isArray)(obj) ? [] : {};
728
714
  visited.set(obj, clone2);
729
715
  for (const key in obj) {
730
- if (Object.prototype.hasOwnProperty.call(obj, key) && !exclude.includes(key)) {
731
- const value = obj[key];
732
- if ((0, import_node.isDOMNode)(value)) {
733
- clone2[key] = value;
734
- } else if (key === "extend" && (0, import_types.isArray)(value)) {
735
- clone2[key] = (0, import_array.mergeArray)(value, exclude);
736
- } else if ((0, import_types.isObjectLike)(value)) {
737
- clone2[key] = deepClone(value, exclude, cleanUndefined, visited);
738
- } else {
739
- clone2[key] = value;
740
- }
741
- }
742
- }
743
- return clone2;
744
- };
745
- var deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}, visited = /* @__PURE__ */ new WeakSet()) => {
746
- if ((0, import_types.isObjectLike)(obj)) {
747
- if (visited.has(obj)) {
748
- return obj;
716
+ if (!Object.prototype.hasOwnProperty.call(obj, key))
717
+ continue;
718
+ if (exclude.includes(key) || key.startsWith("__") || key === "__proto__")
719
+ continue;
720
+ const value = obj[key];
721
+ if (cleanUndefined && (0, import_types.isUndefined)(value) || cleanNull && (0, import_types.isNull)(value))
722
+ continue;
723
+ if ((0, import_node.isDOMNode)(value)) {
724
+ clone2[key] = value;
725
+ continue;
749
726
  }
750
- visited.add(obj);
751
- }
752
- const o = options.window ? (0, import_types.isArray)(obj) ? new options.window.Array([]) : new options.window.Object({}) : (0, import_types.isArray)(obj) ? [] : {};
753
- for (const prop in obj) {
754
- if (!Object.prototype.hasOwnProperty.call(obj, prop))
727
+ if (handleExtend && key === "extend" && (0, import_types.isArray)(value)) {
728
+ clone2[key] = (0, import_array.mergeArray)(value, exclude);
755
729
  continue;
756
- const objProp = obj[prop];
757
- if (excludeFrom.includes(prop) || prop.startsWith("__") || options.cleanUndefined && (0, import_types.isUndefined)(objProp) || options.cleanNull && (0, import_types.isNull)(objProp)) {
730
+ }
731
+ if ((0, import_types.isFunction)(value) && targetWindow) {
732
+ clone2[key] = targetWindow.eval("(" + value.toString() + ")");
758
733
  continue;
759
734
  }
760
- if ((0, import_types.isObjectLike)(objProp)) {
761
- o[prop] = deepCloneWithExtend(objProp, excludeFrom, options, visited);
762
- } else if ((0, import_types.isFunction)(objProp) && options.window) {
763
- o[prop] = (options.window || import_globals.window).eval("(" + objProp.toString() + ")");
735
+ if ((0, import_types.isObjectLike)(value)) {
736
+ clone2[key] = deepClone(value, {
737
+ ...options,
738
+ visited
739
+ });
764
740
  } else {
765
- o[prop] = objProp;
741
+ clone2[key] = value;
766
742
  }
767
743
  }
768
- return o;
744
+ return clone2;
769
745
  };
770
746
  var deepStringify = (obj, stringified = {}) => {
771
747
  var _a, _b;
@@ -1784,7 +1760,7 @@ var require_component = __commonJS({
1784
1760
  if (newChild === null)
1785
1761
  assignChild(null);
1786
1762
  else if (!childElem)
1787
- assignChild((0, import__.deepCloneWithExtend)(newChild));
1763
+ assignChild((0, import__.deepClone)(newChild));
1788
1764
  else {
1789
1765
  const isSugarChildElem = checkIfSugar(childElem, parent, key);
1790
1766
  if (isSugarChildElem)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbo.ls/utils",
3
- "version": "2.11.470",
3
+ "version": "2.11.475",
4
4
  "author": "symbo.ls",
5
5
  "files": [
6
6
  "src",
@@ -19,12 +19,12 @@
19
19
  "build:esm": "npx esbuild ./src/*.js ./src/**/*.js --target=es2017 --format=esm --outdir=dist/esm",
20
20
  "build:cjs": "npx esbuild ./src/*.js ./src/**/*.js --target=node16 --format=cjs --outdir=dist/cjs --bundle",
21
21
  "build:iife": "npx esbuild ./src/index.js --target=es2017 --format=iife --outdir=dist/iife --bundle --minify",
22
- "build": "yarn build:cjs",
23
- "prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
22
+ "build": "npm run build:cjs",
23
+ "prepublish": "rimraf -I dist && npm run build && npm run copy:package:cjs"
24
24
  },
25
25
  "license": "ISC",
26
26
  "dependencies": {
27
27
  "@domql/utils": "^2.5.0"
28
28
  },
29
- "gitHead": "726524dbb01cfa6ead1c95bd8f930a85169c70fe"
29
+ "gitHead": "d2198b5f44d161e2cf0dd8a9d88a5301192bcb02"
30
30
  }