@domql/utils 2.3.117 → 2.3.119

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.
@@ -33,6 +33,7 @@ __export(object_exports, {
33
33
  isEqualDeep: () => isEqualDeep,
34
34
  map: () => map,
35
35
  merge: () => merge,
36
+ mergeArrayExclude: () => mergeArrayExclude,
36
37
  mergeIfExisted: () => mergeIfExisted,
37
38
  overwrite: () => overwrite,
38
39
  overwriteDeep: () => overwriteDeep,
@@ -43,6 +44,7 @@ __export(object_exports, {
43
44
  module.exports = __toCommonJS(object_exports);
44
45
  var import_globals = require("@domql/globals");
45
46
  var import_types = require("./types.js");
47
+ var import_array = require("./array.js");
46
48
  const exec = (param, element, state, context) => {
47
49
  if ((0, import_types.isFunction)(param)) {
48
50
  return param(
@@ -54,30 +56,30 @@ const exec = (param, element, state, context) => {
54
56
  return param;
55
57
  };
56
58
  const map = (obj, extention, element) => {
57
- for (const e2 in extention) {
58
- obj[e2] = exec(extention[e2], element);
59
+ for (const e in extention) {
60
+ obj[e] = exec(extention[e], element);
59
61
  }
60
62
  };
61
63
  const merge = (element, obj) => {
62
- for (const e2 in obj) {
63
- const elementProp = element[e2];
64
- const objProp = obj[e2];
64
+ for (const e in obj) {
65
+ const elementProp = element[e];
66
+ const objProp = obj[e];
65
67
  if (elementProp === void 0) {
66
- element[e2] = objProp;
68
+ element[e] = objProp;
67
69
  }
68
70
  }
69
71
  return element;
70
72
  };
71
73
  const deepMerge = (element, extend, excludeFrom = []) => {
72
- for (const e2 in extend) {
73
- if (excludeFrom.includes(e2) || e2.includes("__"))
74
+ for (const e in extend) {
75
+ if (excludeFrom.includes(e) || e.includes("__"))
74
76
  continue;
75
- const elementProp = element[e2];
76
- const extendProp = extend[e2];
77
+ const elementProp = element[e];
78
+ const extendProp = extend[e];
77
79
  if ((0, import_types.isObjectLike)(elementProp) && (0, import_types.isObjectLike)(extendProp)) {
78
80
  deepMerge(elementProp, extendProp);
79
81
  } else if (elementProp === void 0) {
80
- element[e2] = extendProp;
82
+ element[e] = extendProp;
81
83
  }
82
84
  }
83
85
  return element;
@@ -85,7 +87,7 @@ const deepMerge = (element, extend, excludeFrom = []) => {
85
87
  const clone = (obj, excludeFrom = []) => {
86
88
  const o = {};
87
89
  for (const prop in obj) {
88
- if (excludeFrom.includes(e) || e.includes("__"))
90
+ if (excludeFrom.includes(prop) || prop.includes("__"))
89
91
  continue;
90
92
  o[prop] = obj[prop];
91
93
  }
@@ -112,6 +114,9 @@ const deepCloneExclude = (obj, excludeFrom = []) => {
112
114
  }
113
115
  return o;
114
116
  };
117
+ const mergeArrayExclude = (arr, excl = []) => {
118
+ return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
119
+ };
115
120
  const deepClone = (obj, excludeFrom = []) => {
116
121
  const o = (0, import_types.isArray)(obj) ? [] : {};
117
122
  for (const prop in obj) {
@@ -119,7 +124,7 @@ const deepClone = (obj, excludeFrom = []) => {
119
124
  continue;
120
125
  let objProp = obj[prop];
121
126
  if (prop === "extend" && (0, import_types.isArray)(objProp)) {
122
- objProp = mergeArray(objProp);
127
+ objProp = (0, import_array.mergeArray)(objProp);
123
128
  }
124
129
  if ((0, import_types.isObjectLike)(objProp)) {
125
130
  o[prop] = deepClone(objProp, excludeFrom);
@@ -188,8 +193,8 @@ const deepDestringify = (obj, stringified = {}) => {
188
193
  try {
189
194
  const evalProp = import_globals.window.eval(`(${objProp})`);
190
195
  stringified[prop] = evalProp;
191
- } catch (e2) {
192
- if (e2)
196
+ } catch (e) {
197
+ if (e)
193
198
  stringified[prop] = objProp;
194
199
  }
195
200
  } else {
@@ -203,8 +208,8 @@ const deepDestringify = (obj, stringified = {}) => {
203
208
  try {
204
209
  const evalProp = import_globals.window.eval(`(${arrProp})`);
205
210
  stringified[prop].push(evalProp);
206
- } catch (e2) {
207
- if (e2)
211
+ } catch (e) {
212
+ if (e)
208
213
  stringified[prop].push(arrProp);
209
214
  }
210
215
  } else {
@@ -227,29 +232,29 @@ const deepDestringify = (obj, stringified = {}) => {
227
232
  const overwrite = (element, params, excludeFrom = []) => {
228
233
  const { ref } = element;
229
234
  const changes = {};
230
- for (const e2 in params) {
231
- if (excludeFrom.includes(e2) || e2.includes("__"))
235
+ for (const e in params) {
236
+ if (excludeFrom.includes(e) || e.includes("__"))
232
237
  continue;
233
- const elementProp = element[e2];
234
- const paramsProp = params[e2];
238
+ const elementProp = element[e];
239
+ const paramsProp = params[e];
235
240
  if (paramsProp) {
236
- ref.__cache[e2] = changes[e2] = elementProp;
237
- ref[e2] = paramsProp;
241
+ ref.__cache[e] = changes[e] = elementProp;
242
+ ref[e] = paramsProp;
238
243
  }
239
244
  }
240
245
  return changes;
241
246
  };
242
247
  const diffObjects = (original, objToDiff, cache) => {
243
- for (const e2 in objToDiff) {
244
- if (e2 === "ref")
248
+ for (const e in objToDiff) {
249
+ if (e === "ref")
245
250
  continue;
246
- const originalProp = original[e2];
247
- const objToDiffProp = objToDiff[e2];
251
+ const originalProp = original[e];
252
+ const objToDiffProp = objToDiff[e];
248
253
  if ((0, import_types.isObject)(originalProp) && (0, import_types.isObject)(objToDiffProp)) {
249
- cache[e2] = {};
250
- diff(originalProp, objToDiffProp, cache[e2]);
254
+ cache[e] = {};
255
+ diff(originalProp, objToDiffProp, cache[e]);
251
256
  } else if (objToDiffProp !== void 0) {
252
- cache[e2] = objToDiffProp;
257
+ cache[e] = objToDiffProp;
253
258
  }
254
259
  }
255
260
  return cache;
@@ -282,33 +287,33 @@ const diff = (original, objToDiff, cache = {}) => {
282
287
  };
283
288
  const overwriteObj = (params, obj) => {
284
289
  const changes = {};
285
- for (const e2 in params) {
286
- const objProp = obj[e2];
287
- const paramsProp = params[e2];
290
+ for (const e in params) {
291
+ const objProp = obj[e];
292
+ const paramsProp = params[e];
288
293
  if (paramsProp) {
289
- obj[e2] = changes[e2] = objProp;
294
+ obj[e] = changes[e] = objProp;
290
295
  }
291
296
  }
292
297
  return changes;
293
298
  };
294
299
  const overwriteShallow = (obj, params, excludeFrom = []) => {
295
- for (const e2 in params) {
296
- if (excludeFrom.includes(e2) || e2.includes("__"))
300
+ for (const e in params) {
301
+ if (excludeFrom.includes(e) || e.includes("__"))
297
302
  continue;
298
- obj[e2] = params[e2];
303
+ obj[e] = params[e];
299
304
  }
300
305
  return obj;
301
306
  };
302
307
  const overwriteDeep = (params, obj, excludeFrom = []) => {
303
- for (const e2 in params) {
304
- if (excludeFrom.includes(e2) || e2.includes("__"))
308
+ for (const e in params) {
309
+ if (excludeFrom.includes(e) || e.includes("__"))
305
310
  continue;
306
- const objProp = obj[e2];
307
- const paramsProp = params[e2];
311
+ const objProp = obj[e];
312
+ const paramsProp = params[e];
308
313
  if ((0, import_types.isObjectLike)(objProp) && (0, import_types.isObjectLike)(paramsProp)) {
309
314
  overwriteDeep(paramsProp, objProp);
310
315
  } else if (paramsProp !== void 0) {
311
- obj[e2] = paramsProp;
316
+ obj[e] = paramsProp;
312
317
  }
313
318
  }
314
319
  return obj;
package/object.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { window } from '@domql/globals'
4
4
  import { isFunction, isObjectLike, isObject, isArray, isString, is } from './types.js'
5
-
5
+ import { mergeArray } from './array.js'
6
6
 
7
7
  export const exec = (param, element, state, context) => {
8
8
  if (isFunction(param)) {
@@ -49,7 +49,7 @@ export const deepMerge = (element, extend, excludeFrom = []) => {
49
49
  export const clone = (obj, excludeFrom = []) => {
50
50
  const o = {}
51
51
  for (const prop in obj) {
52
- if (excludeFrom.includes(e) || e.includes('__')) continue
52
+ if (excludeFrom.includes(prop) || prop.includes('__')) continue
53
53
  o[prop] = obj[prop]
54
54
  }
55
55
  return o
@@ -81,6 +81,11 @@ export const deepCloneExclude = (obj, excludeFrom = []) => {
81
81
  return o
82
82
  }
83
83
 
84
+ // Merge array, but exclude keys listed in 'excl'
85
+ export const mergeArrayExclude = (arr, excl = []) => {
86
+ return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {})
87
+ }
88
+
84
89
  /**
85
90
  * Deep cloning of object
86
91
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.3.117",
3
+ "version": "2.3.119",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -23,7 +23,7 @@
23
23
  "@domql/key": "latest",
24
24
  "@domql/tags": "latest"
25
25
  },
26
- "gitHead": "a6da9bf1846e4a1e26017978cf52112b9d61d484",
26
+ "gitHead": "b5b409c827c8b21896d84918f4fe9d133b057916",
27
27
  "devDependencies": {
28
28
  "@babel/core": "^7.12.0"
29
29
  }