@domql/utils 2.5.85 → 2.5.87

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
@@ -7,6 +7,12 @@ export const arrayContainsOtherArray = (arr1, arr2) => {
7
7
  return arr2.every(val => arr1.includes(val))
8
8
  }
9
9
 
10
+ export const getFrequencyInArray = (arr, value) => {
11
+ return arr.reduce((count, currentValue) => {
12
+ return currentValue === value ? count + 1 : count
13
+ }, 0)
14
+ }
15
+
10
16
  export const removeFromArray = (arr, index) => {
11
17
  if (isString(index)) index = parseInt(index)
12
18
  if (isNumber(index)) {
@@ -88,7 +94,7 @@ export const removeValueFromArray = (arr, value) => {
88
94
  newArray.splice(index, 1)
89
95
  return newArray
90
96
  }
91
- return arr.slice()
97
+ return arr
92
98
  }
93
99
 
94
100
  export const removeValueFromArrayAll = (arr, value) => {
package/dist/cjs/array.js CHANGED
@@ -22,6 +22,7 @@ __export(array_exports, {
22
22
  createNestedObject: () => createNestedObject,
23
23
  cutArrayAfterValue: () => cutArrayAfterValue,
24
24
  cutArrayBeforeValue: () => cutArrayBeforeValue,
25
+ getFrequencyInArray: () => getFrequencyInArray,
25
26
  joinArrays: () => joinArrays,
26
27
  mergeAndCloneIfArray: () => mergeAndCloneIfArray,
27
28
  mergeArray: () => mergeArray,
@@ -36,6 +37,11 @@ var import_types = require("./types");
36
37
  const arrayContainsOtherArray = (arr1, arr2) => {
37
38
  return arr2.every((val) => arr1.includes(val));
38
39
  };
40
+ const getFrequencyInArray = (arr, value) => {
41
+ return arr.reduce((count, currentValue) => {
42
+ return currentValue === value ? count + 1 : count;
43
+ }, 0);
44
+ };
39
45
  const removeFromArray = (arr, index) => {
40
46
  if ((0, import_types.isString)(index))
41
47
  index = parseInt(index);
@@ -102,7 +108,7 @@ const removeValueFromArray = (arr, value) => {
102
108
  newArray.splice(index, 1);
103
109
  return newArray;
104
110
  }
105
- return arr.slice();
111
+ return arr;
106
112
  };
107
113
  const removeValueFromArrayAll = (arr, value) => {
108
114
  return arr.filter((item) => item !== value);
@@ -262,7 +262,7 @@ const deepDestringify = (obj, destringified = {}) => {
262
262
  continue;
263
263
  const objProp = obj[prop];
264
264
  if ((0, import_types.isString)(objProp)) {
265
- if (objProp.includes("=>") || objProp.includes("function") || objProp.startsWith("(")) {
265
+ if ((objProp.includes("=>") || objProp.startsWith("function") || objProp.startsWith("(")) && !objProp.startsWith("{") && !objProp.startsWith("[")) {
266
266
  try {
267
267
  const evalProp = import_globals.window.eval(`(${objProp})`);
268
268
  destringified[prop] = evalProp;
package/object.js CHANGED
@@ -190,6 +190,7 @@ export const objectToString = (obj, indent = 0) => {
190
190
  if (isObject(element) && element !== null) {
191
191
  str += `${spaces} ${objectToString(element, indent + 2)},\n`
192
192
  } else if (isString(element)) {
193
+ // if (element.includes('\n')) str += spaces + ' ' + '`' + element + '`,\n'
193
194
  str += `${spaces} '${element}',\n`
194
195
  } else {
195
196
  str += `${spaces} ${element},\n`
@@ -248,9 +249,9 @@ export const deepDestringify = (obj, destringified = {}) => {
248
249
  if (!hasOwnProperty) continue
249
250
  const objProp = obj[prop]
250
251
  if (isString(objProp)) {
251
- if (objProp.includes('=>') || objProp.includes('function') || objProp.startsWith('(')) {
252
+ if ((objProp.includes('=>') || objProp.startsWith('function') || objProp.startsWith('(')) && !objProp.startsWith('{') && !objProp.startsWith('[')) {
252
253
  try {
253
- const evalProp = window.eval(`(${objProp})`) // use parentheses to convert string to function expression
254
+ const evalProp = window.eval(`(${objProp})`)
254
255
  destringified[prop] = evalProp
255
256
  } catch (e) { if (e) destringified[prop] = objProp }
256
257
  } else {
@@ -275,7 +276,7 @@ export const deepDestringify = (obj, destringified = {}) => {
275
276
  }
276
277
  })
277
278
  } else if (isObject(objProp)) {
278
- destringified[prop] = deepDestringify(objProp, destringified[prop]) // recursively call deepDestringify for nested objects
279
+ destringified[prop] = deepDestringify(objProp, destringified[prop])
279
280
  } else {
280
281
  destringified[prop] = objProp
281
282
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.5.85",
3
+ "version": "2.5.87",
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": "d74dca288e3860155be0340404d95a4c872c66aa",
26
+ "gitHead": "59c3f0d7933a32ce68732e2eb448901d63fc0e82",
27
27
  "devDependencies": {
28
28
  "@babel/core": "^7.12.0"
29
29
  }