@domql/utils 2.5.144 → 2.5.148

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
@@ -110,6 +110,7 @@ export const reorderArrayByValues = (array, valueToMove, insertBeforeValue) => {
110
110
  }
111
111
  return newArray
112
112
  }
113
+
113
114
  export const arraysEqual = (arr1, arr2) => {
114
115
  if (arr1.length !== arr2.length) {
115
116
  return false
@@ -123,3 +124,14 @@ export const arraysEqual = (arr1, arr2) => {
123
124
 
124
125
  return true
125
126
  }
127
+
128
+ // Using filter and includes
129
+ export const filterArrays = (sourceArr, excludeArr) => {
130
+ return sourceArr.filter(item => !excludeArr.includes(item))
131
+ }
132
+
133
+ // Using Set for better performance with large arrays
134
+ export const filterArraysFast = (sourceArr, excludeArr) => {
135
+ const excludeSet = new Set(excludeArr)
136
+ return sourceArr.filter(item => !excludeSet.has(item))
137
+ }
package/dist/cjs/array.js CHANGED
@@ -23,6 +23,8 @@ __export(array_exports, {
23
23
  arraysEqual: () => arraysEqual,
24
24
  cutArrayAfterValue: () => cutArrayAfterValue,
25
25
  cutArrayBeforeValue: () => cutArrayBeforeValue,
26
+ filterArrays: () => filterArrays,
27
+ filterArraysFast: () => filterArraysFast,
26
28
  getFrequencyInArray: () => getFrequencyInArray,
27
29
  joinArrays: () => joinArrays,
28
30
  mergeAndCloneIfArray: () => mergeAndCloneIfArray,
@@ -131,3 +133,10 @@ const arraysEqual = (arr1, arr2) => {
131
133
  }
132
134
  return true;
133
135
  };
136
+ const filterArrays = (sourceArr, excludeArr) => {
137
+ return sourceArr.filter((item) => !excludeArr.includes(item));
138
+ };
139
+ const filterArraysFast = (sourceArr, excludeArr) => {
140
+ const excludeSet = new Set(excludeArr);
141
+ return sourceArr.filter((item) => !excludeSet.has(item));
142
+ };
@@ -35,6 +35,7 @@ __export(object_exports, {
35
35
  diff: () => diff,
36
36
  diffArrays: () => diffArrays,
37
37
  diffObjects: () => diffObjects,
38
+ excludeKeysFromObject: () => excludeKeysFromObject,
38
39
  exec: () => exec,
39
40
  flattenRecursive: () => flattenRecursive,
40
41
  hasOwnProperty: () => hasOwnProperty,
@@ -362,7 +363,7 @@ const deepDestringify = (obj, destringified = {}) => {
362
363
  };
363
364
  const stringToObject = (str, opts = { verbose: true }) => {
364
365
  try {
365
- return import_globals.window.eval("(" + str + ")");
366
+ return str ? import_globals.window.eval("(" + str + ")") : {};
366
367
  } catch (e) {
367
368
  if (opts.verbose)
368
369
  console.warn(e);
@@ -442,20 +443,27 @@ const deepDiff = (lhs, rhs) => {
442
443
  return acc;
443
444
  }, deletedValues);
444
445
  };
445
- const overwrite = (element, params, excludeFrom = []) => {
446
- const { ref } = element;
447
- const changes = {};
446
+ const overwrite = (element, params, opts = {}) => {
447
+ const { __ref: ref } = element;
448
+ const excl = opts.exclude || [];
449
+ const allowUnderscore = opts.preventUnderscore;
450
+ const preventCaching = opts.preventCaching;
448
451
  for (const e in params) {
449
- if (excludeFrom.includes(e) || e.startsWith("__"))
452
+ if (excl.includes(e) || !allowUnderscore && e.startsWith("__"))
450
453
  continue;
451
454
  const elementProp = element[e];
452
455
  const paramsProp = params[e];
453
- if (paramsProp) {
454
- ref.__cache[e] = changes[e] = elementProp;
455
- ref[e] = paramsProp;
456
+ if (paramsProp !== void 0) {
457
+ element[e] = paramsProp;
458
+ if (ref && !preventCaching) {
459
+ ref.__cache[e] = elementProp;
460
+ }
461
+ if ((0, import_types.isObject)(opts.diff)) {
462
+ diff[e] = elementProp;
463
+ }
456
464
  }
457
465
  }
458
- return changes;
466
+ return element;
459
467
  };
460
468
  const overwriteShallow = (obj, params, excludeFrom = []) => {
461
469
  for (const e in params) {
@@ -465,23 +473,26 @@ const overwriteShallow = (obj, params, excludeFrom = []) => {
465
473
  }
466
474
  return obj;
467
475
  };
468
- const overwriteDeep = (obj, params, excludeFrom = [], visited = /* @__PURE__ */ new WeakMap()) => {
476
+ const overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new WeakMap()) => {
477
+ const excl = opts.exclude || [];
478
+ const forcedExclude = opts.preventForce ? [] : ["node", "window"];
469
479
  if (!(0, import_types.isObjectLike)(obj) || !(0, import_types.isObjectLike)(params) || (0, import_node.isDOMNode)(obj) || (0, import_node.isDOMNode)(params)) {
470
480
  return params;
471
481
  }
472
- if (visited.has(obj)) {
482
+ if (visited.has(obj))
473
483
  return visited.get(obj);
474
- }
475
484
  visited.set(obj, obj);
476
485
  for (const e in params) {
477
- if (e === "__ref" || excludeFrom.includes(e) || e.startsWith("__"))
486
+ if (!Object.hasOwnProperty.call(params, e))
487
+ continue;
488
+ if (excl.includes(e) || forcedExclude && e.startsWith("__"))
478
489
  continue;
479
490
  const objProp = obj[e];
480
491
  const paramsProp = params[e];
481
492
  if ((0, import_node.isDOMNode)(paramsProp)) {
482
493
  obj[e] = paramsProp;
483
494
  } else if ((0, import_types.isObjectLike)(objProp) && (0, import_types.isObjectLike)(paramsProp)) {
484
- obj[e] = overwriteDeep(objProp, paramsProp, excludeFrom, visited);
495
+ obj[e] = overwriteDeep(objProp, paramsProp, opts, visited);
485
496
  } else if (paramsProp !== void 0) {
486
497
  obj[e] = paramsProp;
487
498
  }
@@ -663,3 +674,8 @@ const isCyclic = (obj) => {
663
674
  }
664
675
  return detect(obj);
665
676
  };
677
+ const excludeKeysFromObject = (obj, excludedKeys) => {
678
+ const result = { ...obj };
679
+ excludedKeys.forEach((key) => delete result[key]);
680
+ return result;
681
+ };
package/object.js CHANGED
@@ -404,7 +404,7 @@ export const deepDestringify = (obj, destringified = {}) => {
404
404
 
405
405
  export const stringToObject = (str, opts = { verbose: true }) => {
406
406
  try {
407
- return window.eval('(' + str + ')') // eslint-disable-line
407
+ return str ? window.eval('(' + str + ')') : {} // eslint-disable-line
408
408
  } catch (e) { if (opts.verbose) console.warn(e) }
409
409
  }
410
410
 
@@ -502,23 +502,30 @@ export const deepDiff = (lhs, rhs) => {
502
502
  /**
503
503
  * Overwrites object properties with another
504
504
  */
505
- export const overwrite = (element, params, excludeFrom = []) => {
506
- const { ref } = element
507
- const changes = {}
505
+ export const overwrite = (element, params, opts = {}) => {
506
+ const { __ref: ref } = element
507
+ const excl = opts.exclude || []
508
+ const allowUnderscore = opts.preventUnderscore
509
+ const preventCaching = opts.preventCaching
508
510
 
509
511
  for (const e in params) {
510
- if (excludeFrom.includes(e) || e.startsWith('__')) continue
512
+ if (excl.includes(e) || (!allowUnderscore && e.startsWith('__'))) continue
511
513
 
512
514
  const elementProp = element[e]
513
515
  const paramsProp = params[e]
514
516
 
515
- if (paramsProp) {
516
- ref.__cache[e] = changes[e] = elementProp
517
- ref[e] = paramsProp
517
+ if (paramsProp !== undefined) {
518
+ element[e] = paramsProp
519
+ if (ref && !preventCaching) {
520
+ ref.__cache[e] = elementProp
521
+ }
522
+ if (isObject(opts.diff)) {
523
+ diff[e] = elementProp
524
+ }
518
525
  }
519
526
  }
520
527
 
521
- return changes
528
+ return element
522
529
  }
523
530
 
524
531
  export const overwriteShallow = (obj, params, excludeFrom = []) => {
@@ -532,19 +539,20 @@ export const overwriteShallow = (obj, params, excludeFrom = []) => {
532
539
  /**
533
540
  * Overwrites DEEPLY object properties with another
534
541
  */
535
- export const overwriteDeep = (obj, params, excludeFrom = [], visited = new WeakMap()) => {
542
+ export const overwriteDeep = (obj, params, opts = {}, visited = new WeakMap()) => {
543
+ const excl = opts.exclude || []
544
+ const forcedExclude = opts.preventForce ? [] : ['node', 'window']
545
+
536
546
  if (!isObjectLike(obj) || !isObjectLike(params) || isDOMNode(obj) || isDOMNode(params)) {
537
547
  return params
538
548
  }
539
549
 
540
- if (visited.has(obj)) {
541
- return visited.get(obj)
542
- }
543
-
550
+ if (visited.has(obj)) return visited.get(obj)
544
551
  visited.set(obj, obj)
545
552
 
546
553
  for (const e in params) {
547
- if (e === '__ref' || excludeFrom.includes(e) || e.startsWith('__')) continue
554
+ if (!Object.hasOwnProperty.call(params, e)) continue
555
+ if (excl.includes(e) || (forcedExclude && e.startsWith('__'))) continue
548
556
 
549
557
  const objProp = obj[e]
550
558
  const paramsProp = params[e]
@@ -552,7 +560,7 @@ export const overwriteDeep = (obj, params, excludeFrom = [], visited = new WeakM
552
560
  if (isDOMNode(paramsProp)) {
553
561
  obj[e] = paramsProp
554
562
  } else if (isObjectLike(objProp) && isObjectLike(paramsProp)) {
555
- obj[e] = overwriteDeep(objProp, paramsProp, excludeFrom, visited)
563
+ obj[e] = overwriteDeep(objProp, paramsProp, opts, visited)
556
564
  } else if (paramsProp !== undefined) {
557
565
  obj[e] = paramsProp
558
566
  }
@@ -817,3 +825,9 @@ export const isCyclic = (obj) => {
817
825
 
818
826
  return detect(obj)
819
827
  }
828
+
829
+ export const excludeKeysFromObject = (obj, excludedKeys) => {
830
+ const result = { ...obj }
831
+ excludedKeys.forEach(key => delete result[key])
832
+ return result
833
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.5.144",
3
+ "version": "2.5.148",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -25,7 +25,7 @@
25
25
  "build": "yarn build:cjs",
26
26
  "prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
27
27
  },
28
- "gitHead": "9026efab1932521ec5eec3e88261eadb81f2e3cb",
28
+ "gitHead": "6706914c73f3c9669ff443c0c890dea1f4e908ab",
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.12.0"
31
31
  }