@domql/utils 2.3.65 → 2.3.70
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/dist/cjs/object.js +108 -75
- package/object.js +46 -13
- package/package.json +5 -8
- package/dist/esm/array.js +0 -0
- package/dist/esm/function.js +0 -26
- package/dist/esm/index.js +0 -6
- package/dist/esm/log.js +0 -15
- package/dist/esm/node.js +0 -15
- package/dist/esm/object.js +0 -238
- package/dist/esm/types.js +0 -72
package/dist/cjs/object.js
CHANGED
|
@@ -39,59 +39,61 @@ __export(object_exports, {
|
|
|
39
39
|
overwriteObj: () => overwriteObj
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(object_exports);
|
|
42
|
+
var import_globals = require("@domql/globals");
|
|
42
43
|
var import_types = require("./types.js");
|
|
43
44
|
const exec = (param, element, state) => {
|
|
44
45
|
if ((0, import_types.isFunction)(param))
|
|
45
46
|
return param(element, state || element.state);
|
|
46
47
|
return param;
|
|
47
48
|
};
|
|
48
|
-
const map = (
|
|
49
|
+
const map = (obj, extention, element) => {
|
|
49
50
|
for (const e in extention) {
|
|
50
|
-
|
|
51
|
+
obj[e] = exec(extention[e], element);
|
|
51
52
|
}
|
|
52
53
|
};
|
|
53
|
-
const merge = (element,
|
|
54
|
-
for (const e in
|
|
54
|
+
const merge = (element, obj) => {
|
|
55
|
+
for (const e in obj) {
|
|
55
56
|
const elementProp = element[e];
|
|
56
|
-
const
|
|
57
|
+
const objProp = obj[e];
|
|
57
58
|
if (elementProp === void 0) {
|
|
58
|
-
element[e] =
|
|
59
|
+
element[e] = objProp;
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
return element;
|
|
62
63
|
};
|
|
63
64
|
const deepMerge = (element, extend) => {
|
|
64
65
|
for (const e in extend) {
|
|
65
|
-
const elementProp = element[e];
|
|
66
66
|
const extendProp = extend[e];
|
|
67
67
|
if (e === "parent" || e === "props")
|
|
68
68
|
continue;
|
|
69
|
-
if (
|
|
69
|
+
if (element[e] === void 0) {
|
|
70
|
+
element[e] = extendProp;
|
|
71
|
+
} else if ((0, import_types.isObjectLike)(element[e]) && (0, import_types.isObjectLike)(extendProp)) {
|
|
72
|
+
deepMerge(element[e], extendProp);
|
|
73
|
+
} else {
|
|
70
74
|
element[e] = extendProp;
|
|
71
|
-
} else if ((0, import_types.isObjectLike)(elementProp) && (0, import_types.isObject)(extendProp)) {
|
|
72
|
-
deepMerge(elementProp, extendProp);
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
return element;
|
|
76
78
|
};
|
|
77
|
-
const clone = (
|
|
79
|
+
const clone = (obj) => {
|
|
78
80
|
const o = {};
|
|
79
|
-
for (const
|
|
80
|
-
if (
|
|
81
|
+
for (const prop in obj) {
|
|
82
|
+
if (prop === "node")
|
|
81
83
|
continue;
|
|
82
|
-
o[
|
|
84
|
+
o[prop] = obj[prop];
|
|
83
85
|
}
|
|
84
86
|
return o;
|
|
85
87
|
};
|
|
86
|
-
const deepCloneExclude = (
|
|
87
|
-
if ((0, import_types.isArray)(
|
|
88
|
-
return
|
|
88
|
+
const deepCloneExclude = (obj, exclude = []) => {
|
|
89
|
+
if ((0, import_types.isArray)(obj)) {
|
|
90
|
+
return obj.map((x) => deepCloneExclude(x, exclude));
|
|
89
91
|
}
|
|
90
92
|
const o = {};
|
|
91
|
-
for (const k in
|
|
93
|
+
for (const k in obj) {
|
|
92
94
|
if (exclude.indexOf(k) > -1)
|
|
93
95
|
continue;
|
|
94
|
-
let v =
|
|
96
|
+
let v = obj[k];
|
|
95
97
|
if (k === "extend" && (0, import_types.isArray)(v)) {
|
|
96
98
|
v = mergeArrayExclude(v, exclude);
|
|
97
99
|
}
|
|
@@ -107,58 +109,89 @@ const deepCloneExclude = (obj2, exclude = []) => {
|
|
|
107
109
|
const mergeArrayExclude = (arr, excl = []) => {
|
|
108
110
|
return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
|
|
109
111
|
};
|
|
110
|
-
const deepClone = (
|
|
111
|
-
if ((0, import_types.isArray)(
|
|
112
|
-
return
|
|
112
|
+
const deepClone = (obj) => {
|
|
113
|
+
if ((0, import_types.isArray)(obj)) {
|
|
114
|
+
return obj.map(deepClone);
|
|
113
115
|
}
|
|
114
116
|
const o = {};
|
|
115
|
-
for (const
|
|
116
|
-
let
|
|
117
|
-
if (
|
|
118
|
-
|
|
117
|
+
for (const prop in obj) {
|
|
118
|
+
let objProp = obj[prop];
|
|
119
|
+
if (prop === "extend" && (0, import_types.isArray)(objProp)) {
|
|
120
|
+
objProp = mergeArray(objProp);
|
|
119
121
|
}
|
|
120
|
-
if ((0, import_types.isArray)(
|
|
121
|
-
o[
|
|
122
|
-
} else if ((0, import_types.isObject)(
|
|
123
|
-
o[
|
|
122
|
+
if ((0, import_types.isArray)(objProp)) {
|
|
123
|
+
o[prop] = objProp.map((v) => (0, import_types.isObject)(v) ? deepClone(v) : v);
|
|
124
|
+
} else if ((0, import_types.isObject)(objProp)) {
|
|
125
|
+
o[prop] = deepClone(objProp);
|
|
124
126
|
} else
|
|
125
|
-
o[
|
|
127
|
+
o[prop] = objProp;
|
|
126
128
|
}
|
|
127
129
|
return o;
|
|
128
130
|
};
|
|
129
|
-
const deepStringify = (
|
|
130
|
-
for (const
|
|
131
|
-
const
|
|
132
|
-
if ((0, import_types.isFunction)(
|
|
133
|
-
|
|
134
|
-
} else if ((0, import_types.isObject)(
|
|
135
|
-
|
|
136
|
-
deepStringify(
|
|
137
|
-
} else if ((0, import_types.isArray)(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
131
|
+
const deepStringify = (obj, stringified = {}) => {
|
|
132
|
+
for (const prop in obj) {
|
|
133
|
+
const objProp = obj[prop];
|
|
134
|
+
if ((0, import_types.isFunction)(objProp)) {
|
|
135
|
+
stringified[prop] = objProp.toString();
|
|
136
|
+
} else if ((0, import_types.isObject)(objProp)) {
|
|
137
|
+
stringified[prop] = {};
|
|
138
|
+
deepStringify(objProp, stringified[prop]);
|
|
139
|
+
} else if ((0, import_types.isArray)(objProp)) {
|
|
140
|
+
stringified[prop] = [];
|
|
141
|
+
objProp.forEach((v, i) => {
|
|
142
|
+
if ((0, import_types.isObject)(v)) {
|
|
143
|
+
stringified[prop][i] = {};
|
|
144
|
+
deepStringify(v, stringified[prop][i]);
|
|
145
|
+
} else if ((0, import_types.isFunction)(v)) {
|
|
146
|
+
stringified[prop][i] = v.toString();
|
|
147
|
+
} else {
|
|
148
|
+
stringified[prop][i] = v;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
stringified[prop] = objProp;
|
|
153
|
+
}
|
|
142
154
|
}
|
|
143
|
-
return
|
|
155
|
+
return stringified;
|
|
144
156
|
};
|
|
145
157
|
const deepDestringify = (obj, stringified = {}) => {
|
|
146
158
|
for (const prop in obj) {
|
|
147
159
|
const objProp = obj[prop];
|
|
148
160
|
if ((0, import_types.isString)(objProp)) {
|
|
149
|
-
if (objProp.includes("=>") || objProp.includes("function") || objProp
|
|
161
|
+
if (objProp.includes("=>") || objProp.includes("function") || objProp.startsWith("(")) {
|
|
150
162
|
try {
|
|
151
|
-
const evalProp = eval(objProp);
|
|
163
|
+
const evalProp = import_globals.window.eval(`(${objProp})`);
|
|
152
164
|
stringified[prop] = evalProp;
|
|
153
165
|
} catch (e) {
|
|
154
166
|
if (e)
|
|
155
167
|
stringified[prop] = objProp;
|
|
156
168
|
}
|
|
157
169
|
}
|
|
158
|
-
} else
|
|
170
|
+
} else {
|
|
159
171
|
stringified[prop] = objProp;
|
|
160
|
-
|
|
161
|
-
|
|
172
|
+
}
|
|
173
|
+
if ((0, import_types.isArray)(objProp)) {
|
|
174
|
+
stringified[prop] = [];
|
|
175
|
+
objProp.forEach((arrProp) => {
|
|
176
|
+
if ((0, import_types.isString)(arrProp)) {
|
|
177
|
+
if (arrProp.includes("=>") || arrProp.includes("function") || arrProp.startsWith("(")) {
|
|
178
|
+
try {
|
|
179
|
+
const evalProp = import_globals.window.eval(arrProp);
|
|
180
|
+
stringified[prop].push(evalProp);
|
|
181
|
+
} catch (e) {
|
|
182
|
+
if (e)
|
|
183
|
+
stringified[prop].push(arrProp);
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
stringified[prop].push(arrProp);
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
stringified[prop].push(deepDestringify(arrProp));
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
} else if ((0, import_types.isObject)(objProp)) {
|
|
193
|
+
stringified[prop] = deepDestringify(objProp, stringified[prop]);
|
|
194
|
+
}
|
|
162
195
|
}
|
|
163
196
|
return stringified;
|
|
164
197
|
};
|
|
@@ -177,44 +210,44 @@ const overwrite = (element, params, options) => {
|
|
|
177
210
|
}
|
|
178
211
|
return changes;
|
|
179
212
|
};
|
|
180
|
-
const diff = (
|
|
213
|
+
const diff = (obj, original, cache) => {
|
|
181
214
|
const changes = cache || {};
|
|
182
|
-
for (const e in
|
|
215
|
+
for (const e in obj) {
|
|
183
216
|
if (e === "ref")
|
|
184
217
|
continue;
|
|
185
218
|
const originalProp = original[e];
|
|
186
|
-
const
|
|
187
|
-
if ((0, import_types.isObjectLike)(originalProp) && (0, import_types.isObjectLike)(
|
|
219
|
+
const objProp = obj[e];
|
|
220
|
+
if ((0, import_types.isObjectLike)(originalProp) && (0, import_types.isObjectLike)(objProp)) {
|
|
188
221
|
changes[e] = {};
|
|
189
|
-
diff(originalProp,
|
|
190
|
-
} else if (
|
|
191
|
-
changes[e] =
|
|
222
|
+
diff(originalProp, objProp, changes[e]);
|
|
223
|
+
} else if (objProp !== void 0) {
|
|
224
|
+
changes[e] = objProp;
|
|
192
225
|
}
|
|
193
226
|
}
|
|
194
227
|
return changes;
|
|
195
228
|
};
|
|
196
|
-
const overwriteObj = (params,
|
|
229
|
+
const overwriteObj = (params, obj) => {
|
|
197
230
|
const changes = {};
|
|
198
231
|
for (const e in params) {
|
|
199
|
-
const
|
|
232
|
+
const objProp = obj[e];
|
|
200
233
|
const paramsProp = params[e];
|
|
201
234
|
if (paramsProp) {
|
|
202
|
-
|
|
235
|
+
obj[e] = changes[e] = objProp;
|
|
203
236
|
}
|
|
204
237
|
}
|
|
205
238
|
return changes;
|
|
206
239
|
};
|
|
207
|
-
const overwriteDeep = (params,
|
|
240
|
+
const overwriteDeep = (params, obj) => {
|
|
208
241
|
for (const e in params) {
|
|
209
|
-
const
|
|
242
|
+
const objProp = obj[e];
|
|
210
243
|
const paramsProp = params[e];
|
|
211
|
-
if ((0, import_types.isObjectLike)(
|
|
212
|
-
overwriteDeep(
|
|
244
|
+
if ((0, import_types.isObjectLike)(objProp) && (0, import_types.isObjectLike)(paramsProp)) {
|
|
245
|
+
overwriteDeep(paramsProp, objProp);
|
|
213
246
|
} else if (paramsProp !== void 0) {
|
|
214
|
-
|
|
247
|
+
obj[e] = paramsProp;
|
|
215
248
|
}
|
|
216
249
|
}
|
|
217
|
-
return
|
|
250
|
+
return obj;
|
|
218
251
|
};
|
|
219
252
|
const mergeIfExisted = (a, b) => {
|
|
220
253
|
if ((0, import_types.isObjectLike)(a) && (0, import_types.isObjectLike)(b))
|
|
@@ -224,16 +257,16 @@ const mergeIfExisted = (a, b) => {
|
|
|
224
257
|
const mergeArray = (arr) => {
|
|
225
258
|
return arr.reduce((a, c) => deepMerge(a, deepClone(c)), {});
|
|
226
259
|
};
|
|
227
|
-
const mergeAndCloneIfArray = (
|
|
228
|
-
return (0, import_types.isArray)(
|
|
260
|
+
const mergeAndCloneIfArray = (obj) => {
|
|
261
|
+
return (0, import_types.isArray)(obj) ? mergeArray(obj) : deepClone(obj);
|
|
229
262
|
};
|
|
230
|
-
const flattenRecursive = (param,
|
|
263
|
+
const flattenRecursive = (param, prop, stack = []) => {
|
|
231
264
|
const objectized = mergeAndCloneIfArray(param);
|
|
232
265
|
stack.push(objectized);
|
|
233
|
-
const extendOfExtend = objectized[
|
|
266
|
+
const extendOfExtend = objectized[prop];
|
|
234
267
|
if (extendOfExtend)
|
|
235
|
-
flattenRecursive(extendOfExtend,
|
|
236
|
-
delete objectized[
|
|
268
|
+
flattenRecursive(extendOfExtend, prop, stack);
|
|
269
|
+
delete objectized[prop];
|
|
237
270
|
return stack;
|
|
238
271
|
};
|
|
239
272
|
const isEqualDeep = (param, element) => {
|
|
@@ -241,9 +274,9 @@ const isEqualDeep = (param, element) => {
|
|
|
241
274
|
return true;
|
|
242
275
|
if (!param || !element)
|
|
243
276
|
return false;
|
|
244
|
-
for (const
|
|
245
|
-
const paramProp = param[
|
|
246
|
-
const elementProp = element[
|
|
277
|
+
for (const prop in param) {
|
|
278
|
+
const paramProp = param[prop];
|
|
279
|
+
const elementProp = element[prop];
|
|
247
280
|
if ((0, import_types.isObjectLike)(paramProp)) {
|
|
248
281
|
const isEqual = isEqualDeep(paramProp, elementProp);
|
|
249
282
|
if (!isEqual)
|
package/object.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
import { window } from '@domql/globals'
|
|
3
4
|
import { isFunction, isObjectLike, isObject, isArray, isString } from './types.js'
|
|
4
5
|
|
|
5
6
|
export const exec = (param, element, state) => {
|
|
@@ -26,14 +27,14 @@ export const merge = (element, obj) => {
|
|
|
26
27
|
|
|
27
28
|
export const deepMerge = (element, extend) => {
|
|
28
29
|
for (const e in extend) {
|
|
29
|
-
const elementProp = element[e]
|
|
30
30
|
const extendProp = extend[e]
|
|
31
|
-
// const cachedProps = cache.props
|
|
32
31
|
if (e === 'parent' || e === 'props') continue
|
|
33
|
-
if (
|
|
32
|
+
if (element[e] === undefined) {
|
|
33
|
+
element[e] = extendProp
|
|
34
|
+
} else if (isObjectLike(element[e]) && isObjectLike(extendProp)) {
|
|
35
|
+
deepMerge(element[e], extendProp)
|
|
36
|
+
} else {
|
|
34
37
|
element[e] = extendProp
|
|
35
|
-
} else if (isObjectLike(elementProp) && isObject(extendProp)) {
|
|
36
|
-
deepMerge(elementProp, extendProp)
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
return element
|
|
@@ -111,11 +112,22 @@ export const deepStringify = (obj, stringified = {}) => {
|
|
|
111
112
|
stringified[prop] = objProp.toString()
|
|
112
113
|
} else if (isObject(objProp)) {
|
|
113
114
|
stringified[prop] = {}
|
|
114
|
-
deepStringify(objProp
|
|
115
|
+
deepStringify(objProp, stringified[prop])
|
|
115
116
|
} else if (isArray(objProp)) {
|
|
116
117
|
stringified[prop] = []
|
|
117
|
-
objProp.
|
|
118
|
-
|
|
118
|
+
objProp.forEach((v, i) => {
|
|
119
|
+
if (isObject(v)) {
|
|
120
|
+
stringified[prop][i] = {}
|
|
121
|
+
deepStringify(v, stringified[prop][i])
|
|
122
|
+
} else if (isFunction(v)) {
|
|
123
|
+
stringified[prop][i] = v.toString()
|
|
124
|
+
} else {
|
|
125
|
+
stringified[prop][i] = v
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
} else {
|
|
129
|
+
stringified[prop] = objProp
|
|
130
|
+
}
|
|
119
131
|
}
|
|
120
132
|
return stringified
|
|
121
133
|
}
|
|
@@ -127,14 +139,35 @@ export const deepDestringify = (obj, stringified = {}) => {
|
|
|
127
139
|
for (const prop in obj) {
|
|
128
140
|
const objProp = obj[prop]
|
|
129
141
|
if (isString(objProp)) {
|
|
130
|
-
if (objProp.includes('=>') || objProp.includes('function') || objProp
|
|
142
|
+
if (objProp.includes('=>') || objProp.includes('function') || objProp.startsWith('(')) {
|
|
131
143
|
try {
|
|
132
|
-
const evalProp = eval(objProp) //
|
|
144
|
+
const evalProp = window.eval(`(${objProp})`) // use parentheses to convert string to function expression
|
|
133
145
|
stringified[prop] = evalProp
|
|
134
146
|
} catch (e) { if (e) stringified[prop] = objProp }
|
|
135
147
|
}
|
|
136
|
-
} else
|
|
137
|
-
|
|
148
|
+
} else {
|
|
149
|
+
stringified[prop] = objProp
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (isArray(objProp)) {
|
|
153
|
+
stringified[prop] = []
|
|
154
|
+
objProp.forEach((arrProp) => {
|
|
155
|
+
if (isString(arrProp)) {
|
|
156
|
+
if (arrProp.includes('=>') || arrProp.includes('function') || arrProp.startsWith('(')) {
|
|
157
|
+
try {
|
|
158
|
+
const evalProp = window.eval(arrProp) // eslint-disable-line
|
|
159
|
+
stringified[prop].push(evalProp)
|
|
160
|
+
} catch (e) { if (e) stringified[prop].push(arrProp) }
|
|
161
|
+
} else {
|
|
162
|
+
stringified[prop].push(arrProp)
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
stringified[prop].push(deepDestringify(arrProp))
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
} else if (isObject(objProp)) {
|
|
169
|
+
stringified[prop] = deepDestringify(objProp, stringified[prop]) // recursively call deepDestringify for nested objects
|
|
170
|
+
}
|
|
138
171
|
}
|
|
139
172
|
return stringified
|
|
140
173
|
}
|
|
@@ -203,7 +236,7 @@ export const overwriteDeep = (params, obj) => {
|
|
|
203
236
|
const objProp = obj[e]
|
|
204
237
|
const paramsProp = params[e]
|
|
205
238
|
if (isObjectLike(objProp) && isObjectLike(paramsProp)) {
|
|
206
|
-
overwriteDeep(
|
|
239
|
+
overwriteDeep(paramsProp, objProp)
|
|
207
240
|
} else if (paramsProp !== undefined) {
|
|
208
241
|
obj[e] = paramsProp
|
|
209
242
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.70",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"module": "
|
|
7
|
-
"
|
|
8
|
-
"jsdelivr": "dist/iife/index.js",
|
|
9
|
-
"main": "dist/esm/index.js",
|
|
6
|
+
"module": "index.js",
|
|
7
|
+
"main": "index.js",
|
|
10
8
|
"exports": "./dist/cjs/index.js",
|
|
11
9
|
"source": "index.js",
|
|
12
10
|
"files": [
|
|
@@ -17,13 +15,12 @@
|
|
|
17
15
|
"copy:package:cjs": "cp ../../.build/package-cjs.json dist/cjs/package.json",
|
|
18
16
|
"build:esm": "npx esbuild *.js --target=es2020 --format=esm --outdir=dist/esm",
|
|
19
17
|
"build:cjs": "npx esbuild *.js --target=node16 --format=cjs --outdir=dist/cjs",
|
|
20
|
-
"build
|
|
21
|
-
"build": "yarn build:esm && yarn build:cjs",
|
|
18
|
+
"build": "yarn build:cjs",
|
|
22
19
|
"prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
|
|
23
20
|
},
|
|
24
21
|
"dependencies": {
|
|
25
22
|
"@domql/globals": "latest",
|
|
26
23
|
"@domql/tags": "latest"
|
|
27
24
|
},
|
|
28
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "c2fa4c40d134093b837eafc1c4374561032281bf"
|
|
29
26
|
}
|
package/dist/esm/array.js
DELETED
|
File without changes
|
package/dist/esm/function.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const debounce = (element, func, timeout = 300) => {
|
|
2
|
-
let timer;
|
|
3
|
-
return (...args) => {
|
|
4
|
-
clearTimeout(timer);
|
|
5
|
-
timer = setTimeout(() => {
|
|
6
|
-
func.apply(element, args);
|
|
7
|
-
}, timeout);
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
const memoize = (fn) => {
|
|
11
|
-
const cache = {};
|
|
12
|
-
return (...args) => {
|
|
13
|
-
const n = args[0];
|
|
14
|
-
if (n in cache) {
|
|
15
|
-
return cache[n];
|
|
16
|
-
} else {
|
|
17
|
-
const result = fn(n);
|
|
18
|
-
cache[n] = result;
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
export {
|
|
24
|
-
debounce,
|
|
25
|
-
memoize
|
|
26
|
-
};
|
package/dist/esm/index.js
DELETED
package/dist/esm/log.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const logIf = (bool, ...arg) => {
|
|
2
|
-
if (bool)
|
|
3
|
-
arg.map((v) => console.log(v));
|
|
4
|
-
};
|
|
5
|
-
const logGroupIf = (bool, key, ...arg) => {
|
|
6
|
-
if (bool) {
|
|
7
|
-
console.group(key);
|
|
8
|
-
arg.map((v) => console.log(v));
|
|
9
|
-
console.groupEnd(key);
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
export {
|
|
13
|
-
logGroupIf,
|
|
14
|
-
logIf
|
|
15
|
-
};
|
package/dist/esm/node.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const cleanWithNode = (extend) => delete extend.node && extend;
|
|
2
|
-
const createID = function() {
|
|
3
|
-
let index = 0;
|
|
4
|
-
function newId() {
|
|
5
|
-
index++;
|
|
6
|
-
return index;
|
|
7
|
-
}
|
|
8
|
-
return newId;
|
|
9
|
-
}();
|
|
10
|
-
const createSnapshotId = createID;
|
|
11
|
-
export {
|
|
12
|
-
cleanWithNode,
|
|
13
|
-
createID,
|
|
14
|
-
createSnapshotId
|
|
15
|
-
};
|
package/dist/esm/object.js
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import { isFunction, isObjectLike, isObject, isArray, isString } from "./types.js";
|
|
2
|
-
const exec = (param, element, state) => {
|
|
3
|
-
if (isFunction(param))
|
|
4
|
-
return param(element, state || element.state);
|
|
5
|
-
return param;
|
|
6
|
-
};
|
|
7
|
-
const map = (obj2, extention, element) => {
|
|
8
|
-
for (const e in extention) {
|
|
9
|
-
obj2[e] = exec(extention[e], element);
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
const merge = (element, obj2) => {
|
|
13
|
-
for (const e in obj2) {
|
|
14
|
-
const elementProp = element[e];
|
|
15
|
-
const objProp2 = obj2[e];
|
|
16
|
-
if (elementProp === void 0) {
|
|
17
|
-
element[e] = objProp2;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return element;
|
|
21
|
-
};
|
|
22
|
-
const deepMerge = (element, extend) => {
|
|
23
|
-
for (const e in extend) {
|
|
24
|
-
const elementProp = element[e];
|
|
25
|
-
const extendProp = extend[e];
|
|
26
|
-
if (e === "parent" || e === "props")
|
|
27
|
-
continue;
|
|
28
|
-
if (elementProp === void 0) {
|
|
29
|
-
element[e] = extendProp;
|
|
30
|
-
} else if (isObjectLike(elementProp) && isObject(extendProp)) {
|
|
31
|
-
deepMerge(elementProp, extendProp);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return element;
|
|
35
|
-
};
|
|
36
|
-
const clone = (obj2) => {
|
|
37
|
-
const o = {};
|
|
38
|
-
for (const prop2 in obj2) {
|
|
39
|
-
if (prop2 === "node")
|
|
40
|
-
continue;
|
|
41
|
-
o[prop2] = obj2[prop2];
|
|
42
|
-
}
|
|
43
|
-
return o;
|
|
44
|
-
};
|
|
45
|
-
const deepCloneExclude = (obj2, exclude = []) => {
|
|
46
|
-
if (isArray(obj2)) {
|
|
47
|
-
return obj2.map((x) => deepCloneExclude(x, exclude));
|
|
48
|
-
}
|
|
49
|
-
const o = {};
|
|
50
|
-
for (const k in obj2) {
|
|
51
|
-
if (exclude.indexOf(k) > -1)
|
|
52
|
-
continue;
|
|
53
|
-
let v = obj2[k];
|
|
54
|
-
if (k === "extend" && isArray(v)) {
|
|
55
|
-
v = mergeArrayExclude(v, exclude);
|
|
56
|
-
}
|
|
57
|
-
if (isArray(v)) {
|
|
58
|
-
o[k] = v.map((x) => deepCloneExclude(x, exclude));
|
|
59
|
-
} else if (isObject(v)) {
|
|
60
|
-
o[k] = deepCloneExclude(v, exclude);
|
|
61
|
-
} else
|
|
62
|
-
o[k] = v;
|
|
63
|
-
}
|
|
64
|
-
return o;
|
|
65
|
-
};
|
|
66
|
-
const mergeArrayExclude = (arr, excl = []) => {
|
|
67
|
-
return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
|
|
68
|
-
};
|
|
69
|
-
const deepClone = (obj2) => {
|
|
70
|
-
if (isArray(obj2)) {
|
|
71
|
-
return obj2.map(deepClone);
|
|
72
|
-
}
|
|
73
|
-
const o = {};
|
|
74
|
-
for (const prop2 in obj2) {
|
|
75
|
-
let objProp2 = obj2[prop2];
|
|
76
|
-
if (prop2 === "extend" && isArray(objProp2)) {
|
|
77
|
-
objProp2 = mergeArray(objProp2);
|
|
78
|
-
}
|
|
79
|
-
if (isArray(objProp2)) {
|
|
80
|
-
o[prop2] = objProp2.map((v) => isObject(v) ? deepClone(v) : v);
|
|
81
|
-
} else if (isObject(objProp2)) {
|
|
82
|
-
o[prop2] = deepClone(objProp2);
|
|
83
|
-
} else
|
|
84
|
-
o[prop2] = objProp2;
|
|
85
|
-
}
|
|
86
|
-
return o;
|
|
87
|
-
};
|
|
88
|
-
const deepStringify = (obj2, stringified2 = {}) => {
|
|
89
|
-
for (const prop2 in obj2) {
|
|
90
|
-
const objProp2 = obj2[prop2];
|
|
91
|
-
if (isFunction(objProp2)) {
|
|
92
|
-
stringified2[prop2] = objProp2.toString();
|
|
93
|
-
} else if (isObject(objProp2)) {
|
|
94
|
-
stringified2[prop2] = {};
|
|
95
|
-
deepStringify(objProp2[prop2], stringified2[prop2]);
|
|
96
|
-
} else if (isArray(objProp2)) {
|
|
97
|
-
stringified2[prop2] = [];
|
|
98
|
-
objProp2.map((v, i) => deepStringify(v, stringified2[prop2][i]));
|
|
99
|
-
} else
|
|
100
|
-
stringified2[prop2] = objProp2;
|
|
101
|
-
}
|
|
102
|
-
return stringified2;
|
|
103
|
-
};
|
|
104
|
-
const deepDestringify = (obj, stringified = {}) => {
|
|
105
|
-
for (const prop in obj) {
|
|
106
|
-
const objProp = obj[prop];
|
|
107
|
-
if (isString(objProp)) {
|
|
108
|
-
if (objProp.includes("=>") || objProp.includes("function") || objProp[0] === "(") {
|
|
109
|
-
try {
|
|
110
|
-
const evalProp = eval(objProp);
|
|
111
|
-
stringified[prop] = evalProp;
|
|
112
|
-
} catch (e) {
|
|
113
|
-
if (e)
|
|
114
|
-
stringified[prop] = objProp;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
} else
|
|
118
|
-
stringified[prop] = objProp;
|
|
119
|
-
if (isObject(objProp))
|
|
120
|
-
deepDestringify(stringified[prop], stringified[prop]);
|
|
121
|
-
}
|
|
122
|
-
return stringified;
|
|
123
|
-
};
|
|
124
|
-
const overwrite = (element, params, options) => {
|
|
125
|
-
const { ref } = element;
|
|
126
|
-
const changes = {};
|
|
127
|
-
for (const e in params) {
|
|
128
|
-
if (e === "props")
|
|
129
|
-
continue;
|
|
130
|
-
const elementProp = element[e];
|
|
131
|
-
const paramsProp = params[e];
|
|
132
|
-
if (paramsProp) {
|
|
133
|
-
ref.__cache[e] = changes[e] = elementProp;
|
|
134
|
-
ref[e] = paramsProp;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return changes;
|
|
138
|
-
};
|
|
139
|
-
const diff = (obj2, original, cache) => {
|
|
140
|
-
const changes = cache || {};
|
|
141
|
-
for (const e in obj2) {
|
|
142
|
-
if (e === "ref")
|
|
143
|
-
continue;
|
|
144
|
-
const originalProp = original[e];
|
|
145
|
-
const objProp2 = obj2[e];
|
|
146
|
-
if (isObjectLike(originalProp) && isObjectLike(objProp2)) {
|
|
147
|
-
changes[e] = {};
|
|
148
|
-
diff(originalProp, objProp2, changes[e]);
|
|
149
|
-
} else if (objProp2 !== void 0) {
|
|
150
|
-
changes[e] = objProp2;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return changes;
|
|
154
|
-
};
|
|
155
|
-
const overwriteObj = (params, obj2) => {
|
|
156
|
-
const changes = {};
|
|
157
|
-
for (const e in params) {
|
|
158
|
-
const objProp2 = obj2[e];
|
|
159
|
-
const paramsProp = params[e];
|
|
160
|
-
if (paramsProp) {
|
|
161
|
-
obj2[e] = changes[e] = objProp2;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return changes;
|
|
165
|
-
};
|
|
166
|
-
const overwriteDeep = (params, obj2) => {
|
|
167
|
-
for (const e in params) {
|
|
168
|
-
const objProp2 = obj2[e];
|
|
169
|
-
const paramsProp = params[e];
|
|
170
|
-
if (isObjectLike(objProp2) && isObjectLike(paramsProp)) {
|
|
171
|
-
overwriteDeep(objProp2, paramsProp);
|
|
172
|
-
} else if (paramsProp !== void 0) {
|
|
173
|
-
obj2[e] = paramsProp;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return obj2;
|
|
177
|
-
};
|
|
178
|
-
const mergeIfExisted = (a, b) => {
|
|
179
|
-
if (isObjectLike(a) && isObjectLike(b))
|
|
180
|
-
return deepMerge(a, b);
|
|
181
|
-
return a || b;
|
|
182
|
-
};
|
|
183
|
-
const mergeArray = (arr) => {
|
|
184
|
-
return arr.reduce((a, c) => deepMerge(a, deepClone(c)), {});
|
|
185
|
-
};
|
|
186
|
-
const mergeAndCloneIfArray = (obj2) => {
|
|
187
|
-
return isArray(obj2) ? mergeArray(obj2) : deepClone(obj2);
|
|
188
|
-
};
|
|
189
|
-
const flattenRecursive = (param, prop2, stack = []) => {
|
|
190
|
-
const objectized = mergeAndCloneIfArray(param);
|
|
191
|
-
stack.push(objectized);
|
|
192
|
-
const extendOfExtend = objectized[prop2];
|
|
193
|
-
if (extendOfExtend)
|
|
194
|
-
flattenRecursive(extendOfExtend, prop2, stack);
|
|
195
|
-
delete objectized[prop2];
|
|
196
|
-
return stack;
|
|
197
|
-
};
|
|
198
|
-
const isEqualDeep = (param, element) => {
|
|
199
|
-
if (param === element)
|
|
200
|
-
return true;
|
|
201
|
-
if (!param || !element)
|
|
202
|
-
return false;
|
|
203
|
-
for (const prop2 in param) {
|
|
204
|
-
const paramProp = param[prop2];
|
|
205
|
-
const elementProp = element[prop2];
|
|
206
|
-
if (isObjectLike(paramProp)) {
|
|
207
|
-
const isEqual = isEqualDeep(paramProp, elementProp);
|
|
208
|
-
if (!isEqual)
|
|
209
|
-
return false;
|
|
210
|
-
} else {
|
|
211
|
-
const isEqual = paramProp === elementProp;
|
|
212
|
-
if (!isEqual)
|
|
213
|
-
return false;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
return true;
|
|
217
|
-
};
|
|
218
|
-
export {
|
|
219
|
-
clone,
|
|
220
|
-
deepClone,
|
|
221
|
-
deepCloneExclude,
|
|
222
|
-
deepDestringify,
|
|
223
|
-
deepMerge,
|
|
224
|
-
deepStringify,
|
|
225
|
-
diff,
|
|
226
|
-
exec,
|
|
227
|
-
flattenRecursive,
|
|
228
|
-
isEqualDeep,
|
|
229
|
-
map,
|
|
230
|
-
merge,
|
|
231
|
-
mergeAndCloneIfArray,
|
|
232
|
-
mergeArray,
|
|
233
|
-
mergeArrayExclude,
|
|
234
|
-
mergeIfExisted,
|
|
235
|
-
overwrite,
|
|
236
|
-
overwriteDeep,
|
|
237
|
-
overwriteObj
|
|
238
|
-
};
|
package/dist/esm/types.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { window } from "@domql/globals";
|
|
2
|
-
import { HTML_TAGS } from "@domql/tags";
|
|
3
|
-
const isValidHtmlTag = (arg) => HTML_TAGS.body.indexOf(arg);
|
|
4
|
-
const isObject = (arg) => {
|
|
5
|
-
if (arg === null)
|
|
6
|
-
return false;
|
|
7
|
-
return typeof arg === "object" && arg.constructor === Object;
|
|
8
|
-
};
|
|
9
|
-
const isString = (arg) => typeof arg === "string";
|
|
10
|
-
const isNumber = (arg) => typeof arg === "number";
|
|
11
|
-
const isFunction = (arg) => typeof arg === "function";
|
|
12
|
-
const isBoolean = (arg) => arg === true || arg === false;
|
|
13
|
-
const isNull = (arg) => arg === null;
|
|
14
|
-
const isArray = (arg) => Array.isArray(arg);
|
|
15
|
-
const isObjectLike = (arg) => {
|
|
16
|
-
if (arg === null)
|
|
17
|
-
return false;
|
|
18
|
-
return typeof arg === "object";
|
|
19
|
-
};
|
|
20
|
-
const isNode = (obj) => {
|
|
21
|
-
return typeof window.Node === "object" ? obj instanceof window.Node : obj && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string";
|
|
22
|
-
};
|
|
23
|
-
const isHtmlElement = (obj) => {
|
|
24
|
-
return typeof window.HTMLElement === "object" ? obj instanceof window.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string";
|
|
25
|
-
};
|
|
26
|
-
const isDefined = (arg) => {
|
|
27
|
-
return isObject(arg) || isObjectLike(arg) || isString(arg) || isNumber(arg) || isFunction(arg) || isArray(arg) || isObjectLike(arg) || isBoolean(arg) || isNull(arg);
|
|
28
|
-
};
|
|
29
|
-
const isUndefined = (arg) => {
|
|
30
|
-
return arg === void 0;
|
|
31
|
-
};
|
|
32
|
-
const TYPES = {
|
|
33
|
-
boolean: isBoolean,
|
|
34
|
-
array: isArray,
|
|
35
|
-
object: isObject,
|
|
36
|
-
string: isString,
|
|
37
|
-
number: isNumber,
|
|
38
|
-
null: isNull,
|
|
39
|
-
function: isFunction,
|
|
40
|
-
objectLike: isObjectLike,
|
|
41
|
-
node: isNode,
|
|
42
|
-
htmlElement: isHtmlElement,
|
|
43
|
-
defined: isDefined
|
|
44
|
-
};
|
|
45
|
-
const is = (arg) => {
|
|
46
|
-
return (...args) => {
|
|
47
|
-
return args.map((val) => TYPES[val](arg)).filter((v) => v).length > 0;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
const isNot = (arg) => {
|
|
51
|
-
return (...args) => {
|
|
52
|
-
return args.map((val) => TYPES[val](arg)).filter((v) => v).length === 0;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
export {
|
|
56
|
-
TYPES,
|
|
57
|
-
is,
|
|
58
|
-
isArray,
|
|
59
|
-
isBoolean,
|
|
60
|
-
isDefined,
|
|
61
|
-
isFunction,
|
|
62
|
-
isHtmlElement,
|
|
63
|
-
isNode,
|
|
64
|
-
isNot,
|
|
65
|
-
isNull,
|
|
66
|
-
isNumber,
|
|
67
|
-
isObject,
|
|
68
|
-
isObjectLike,
|
|
69
|
-
isString,
|
|
70
|
-
isUndefined,
|
|
71
|
-
isValidHtmlTag
|
|
72
|
-
};
|