@domql/utils 2.3.24 → 2.3.26

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.
Files changed (3) hide show
  1. package/object.js +43 -2
  2. package/package.json +2 -3
  3. package/LICENSE +0 -21
package/object.js CHANGED
@@ -48,6 +48,37 @@ export const clone = obj => {
48
48
  return o
49
49
  }
50
50
 
51
+ // Clone anything deeply but exclude keys given in 'exclude'
52
+ export const deepCloneExclude(obj, exclude = []) {
53
+ if (isArray(obj)) {
54
+ return obj.map(x => deepCloneExclude(x, exclude))
55
+ }
56
+
57
+ const o = {}
58
+ for (const k in obj) {
59
+ if (exclude.indexOf(k) > -1) continue
60
+
61
+ let v = obj[k]
62
+
63
+ if (k === 'extend' && isArray(v)) {
64
+ v = mergeArrayExclude(v, exclude)
65
+ }
66
+
67
+ if (isArray(v)) {
68
+ o[k] = v.map(x => deepCloneExclude(x, exclude))
69
+ } else if (isObject(v)) {
70
+ o[k] = deepCloneExclude(v, exclude)
71
+ } else o[k] = v
72
+ }
73
+
74
+ return o
75
+ }
76
+
77
+ // Merge array, but exclude keys listed in 'excl'
78
+ export const mergeArrayExclude = (arr, excl = []) => {
79
+ return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {})
80
+ }
81
+
51
82
  /**
52
83
  * Deep cloning of object
53
84
  */
@@ -79,6 +110,10 @@ export const deepStringify = (obj, stringified = {}) => {
79
110
  if (isFunction(objProp)) {
80
111
  stringified[prop] = objProp.toString()
81
112
  } else stringified[prop] = objProp
113
+ // if (prop === 'src') {
114
+ // console.log(typeof stringified[prop])
115
+ // console.log(prop, stringified[prop])
116
+ // }
82
117
  if (isObject(objProp)) deepStringify(stringified[prop], stringified[prop])
83
118
  }
84
119
  return stringified
@@ -91,10 +126,16 @@ export const deepDestringify = (obj, stringified = {}) => {
91
126
  for (const prop in obj) {
92
127
  const objProp = obj[prop]
93
128
  if (isString(objProp)) {
94
- if (objProp.slice(0, 1) === '(') {
129
+ if (objProp.includes('=>') || objProp.includes('function') || objProp[0] === '(') {
130
+ // console.groupCollapsed(prop)
131
+ // console.log(obj)
132
+ // console.log(objProp)
95
133
  try {
96
- stringified[prop] = eval(objProp) // eslint-disable-line
134
+ const evalProp = eval(objProp) // eslint-disable-line
135
+ // console.log(evalProp)
136
+ stringified[prop] = evalProp
97
137
  } catch (e) { if (e) stringified[prop] = objProp }
138
+ // console.groupEnd(prop)
98
139
  }
99
140
  } else stringified[prop] = objProp
100
141
  if (isObject(objProp)) deepDestringify(stringified[prop], stringified[prop])
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.3.24",
3
+ "version": "2.3.26",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
8
  "@domql/globals": "latest",
9
9
  "@domql/tags": "latest"
10
- },
11
- "gitHead": "1b912f1758896a2721daf5fed681290833ee9a4d"
10
+ }
12
11
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2016 rackai
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.