@domql/utils 2.5.18 → 2.5.22

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
@@ -79,3 +79,17 @@ export const createNestedObject = (arr, lastValue) => {
79
79
 
80
80
  return nestedObject
81
81
  }
82
+
83
+ export const removeValueFromArray = (arr, value) => {
84
+ const index = arr.indexOf(value)
85
+ if (index > -1) {
86
+ const newArray = [...arr]
87
+ newArray.splice(index, 1)
88
+ return newArray
89
+ }
90
+ return arr.slice()
91
+ }
92
+
93
+ export const removeValueFromArrayAll = (arr, value) => {
94
+ return arr.filter(item => item !== value)
95
+ }
package/dist/cjs/array.js CHANGED
@@ -26,6 +26,8 @@ __export(array_exports, {
26
26
  mergeAndCloneIfArray: () => mergeAndCloneIfArray,
27
27
  mergeArray: () => mergeArray,
28
28
  removeFromArray: () => removeFromArray,
29
+ removeValueFromArray: () => removeValueFromArray,
30
+ removeValueFromArrayAll: () => removeValueFromArrayAll,
29
31
  swapItemsInArray: () => swapItemsInArray
30
32
  });
31
33
  module.exports = __toCommonJS(array_exports);
@@ -91,3 +93,15 @@ const createNestedObject = (arr, lastValue) => {
91
93
  }, nestedObject);
92
94
  return nestedObject;
93
95
  };
96
+ const removeValueFromArray = (arr, value) => {
97
+ const index = arr.indexOf(value);
98
+ if (index > -1) {
99
+ const newArray = [...arr];
100
+ newArray.splice(index, 1);
101
+ return newArray;
102
+ }
103
+ return arr.slice();
104
+ };
105
+ const removeValueFromArrayAll = (arr, value) => {
106
+ return arr.filter((item) => item !== value);
107
+ };
@@ -128,7 +128,7 @@ const deepCloneExclude = (obj, excludeFrom = []) => {
128
128
  const mergeArrayExclude = (arr, excl = []) => {
129
129
  return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
130
130
  };
131
- const deepClone = (obj, excludeFrom = []) => {
131
+ const deepClone = (obj, excludeFrom = [], cleanUndefined = false) => {
132
132
  const o = (0, import_types.isArray)(obj) ? [] : {};
133
133
  for (const prop in obj) {
134
134
  if (prop === "__proto__")
@@ -136,11 +136,13 @@ const deepClone = (obj, excludeFrom = []) => {
136
136
  if (excludeFrom.includes(prop) || prop.startsWith("__"))
137
137
  continue;
138
138
  let objProp = obj[prop];
139
+ if (cleanUndefined && (0, import_types.isUndefined)(objProp))
140
+ continue;
139
141
  if (prop === "extend" && (0, import_types.isArray)(objProp)) {
140
142
  objProp = (0, import_array.mergeArray)(objProp);
141
143
  }
142
144
  if ((0, import_types.isObjectLike)(objProp)) {
143
- o[prop] = deepClone(objProp, excludeFrom);
145
+ o[prop] = deepClone(objProp, excludeFrom, cleanUndefined);
144
146
  } else
145
147
  o[prop] = objProp;
146
148
  }
@@ -194,7 +196,7 @@ const objectToString = (obj, indent = 0) => {
194
196
  }
195
197
  }
196
198
  str += `${spaces} ]`;
197
- } else if ((0, import_types.isObject)(value)) {
199
+ } else if ((0, import_types.isObjectLike)(value)) {
198
200
  str += objectToString(value, indent + 1);
199
201
  } else if ((0, import_types.isString)(value)) {
200
202
  str += (0, import_string.stringIncludesAny)(value, ["\n", "'"]) ? `\`${value}\`` : `'${value}'`;
package/object.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  import { window } from './globals.js'
4
- import { isFunction, isObjectLike, isObject, isArray, isString, is } from './types.js'
4
+ import { isFunction, isObjectLike, isObject, isArray, isString, is, isUndefined } from './types.js'
5
5
  import { mergeAndCloneIfArray, mergeArray } from './array.js'
6
6
  import { stringIncludesAny } from './string.js'
7
7
  import { diff as deepObjectDiff } from 'deep-object-diff'
@@ -96,17 +96,18 @@ export const mergeArrayExclude = (arr, excl = []) => {
96
96
  /**
97
97
  * Deep cloning of object
98
98
  */
99
- export const deepClone = (obj, excludeFrom = []) => {
99
+ export const deepClone = (obj, excludeFrom = [], cleanUndefined = false) => {
100
100
  const o = isArray(obj) ? [] : {}
101
101
  for (const prop in obj) {
102
102
  if (prop === '__proto__') continue
103
103
  if (excludeFrom.includes(prop) || prop.startsWith('__')) continue
104
104
  let objProp = obj[prop]
105
+ if (cleanUndefined && isUndefined(objProp)) continue
105
106
  if (prop === 'extend' && isArray(objProp)) {
106
107
  objProp = mergeArray(objProp)
107
108
  }
108
109
  if (isObjectLike(objProp)) {
109
- o[prop] = deepClone(objProp, excludeFrom)
110
+ o[prop] = deepClone(objProp, excludeFrom, cleanUndefined)
110
111
  } else o[prop] = objProp
111
112
  }
112
113
  return o
@@ -163,7 +164,7 @@ export const objectToString = (obj, indent = 0) => {
163
164
  }
164
165
  }
165
166
  str += `${spaces} ]`
166
- } else if (isObject(value)) {
167
+ } else if (isObjectLike(value)) {
167
168
  str += objectToString(value, indent + 1)
168
169
  } else if (isString(value)) {
169
170
  str += stringIncludesAny(value, ['\n', '\'']) ? `\`${value}\`` : `'${value}'`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.5.18",
3
+ "version": "2.5.22",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -23,7 +23,7 @@
23
23
  "build": "yarn build:cjs",
24
24
  "prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
25
25
  },
26
- "gitHead": "4aeead0b153d4cd5430694ecf45a5d3052f9f9f5",
26
+ "gitHead": "231fe90e14adace5408e9f5def451463ec1430ae",
27
27
  "devDependencies": {
28
28
  "@babel/core": "^7.12.0"
29
29
  },