@domql/utils 2.3.138 → 2.3.142
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 +36 -0
- package/dist/cjs/array.js +33 -0
- package/dist/cjs/object.js +10 -8
- package/object.js +9 -8
- package/package.json +2 -2
package/array.js
CHANGED
|
@@ -43,3 +43,39 @@ export const mergeArray = (arr, excludeFrom = []) => {
|
|
|
43
43
|
export const mergeAndCloneIfArray = obj => {
|
|
44
44
|
return isArray(obj) ? mergeArray(obj) : deepClone(obj)
|
|
45
45
|
}
|
|
46
|
+
|
|
47
|
+
export const cutArrayBeforeValue = (arr, value) => {
|
|
48
|
+
const index = arr.indexOf(value);
|
|
49
|
+
if (index !== -1) {
|
|
50
|
+
return arr.slice(0, index);
|
|
51
|
+
}
|
|
52
|
+
return arr;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const cutArrayAfterValue = (arr, value) => {
|
|
56
|
+
const index = arr.indexOf(value);
|
|
57
|
+
if (index !== -1) {
|
|
58
|
+
return arr.slice(index + 1);
|
|
59
|
+
}
|
|
60
|
+
return arr;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const createNestedObject = (arr, lastValue) => {
|
|
64
|
+
let nestedObject = {};
|
|
65
|
+
|
|
66
|
+
if (arr.length === 0) {
|
|
67
|
+
return lastValue;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
arr.reduce((obj, value, index) => {
|
|
71
|
+
if (!obj[value]) {
|
|
72
|
+
obj[value] = {};
|
|
73
|
+
}
|
|
74
|
+
if (index === arr.length - 1 && lastValue) {
|
|
75
|
+
obj[value] = lastValue;
|
|
76
|
+
}
|
|
77
|
+
return obj[value];
|
|
78
|
+
}, nestedObject);
|
|
79
|
+
|
|
80
|
+
return nestedObject;
|
|
81
|
+
}
|
package/dist/cjs/array.js
CHANGED
|
@@ -19,6 +19,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var array_exports = {};
|
|
20
20
|
__export(array_exports, {
|
|
21
21
|
arrayContainsOtherArray: () => arrayContainsOtherArray,
|
|
22
|
+
createNestedObject: () => createNestedObject,
|
|
23
|
+
cutArrayAfterValue: () => cutArrayAfterValue,
|
|
24
|
+
cutArrayBeforeValue: () => cutArrayBeforeValue,
|
|
22
25
|
joinArrays: () => joinArrays,
|
|
23
26
|
mergeAndCloneIfArray: () => mergeAndCloneIfArray,
|
|
24
27
|
mergeArray: () => mergeArray,
|
|
@@ -58,3 +61,33 @@ const mergeArray = (arr, excludeFrom = []) => {
|
|
|
58
61
|
const mergeAndCloneIfArray = (obj) => {
|
|
59
62
|
return (0, import_types.isArray)(obj) ? mergeArray(obj) : (0, import_object.deepClone)(obj);
|
|
60
63
|
};
|
|
64
|
+
const cutArrayBeforeValue = (arr, value) => {
|
|
65
|
+
const index = arr.indexOf(value);
|
|
66
|
+
if (index !== -1) {
|
|
67
|
+
return arr.slice(0, index);
|
|
68
|
+
}
|
|
69
|
+
return arr;
|
|
70
|
+
};
|
|
71
|
+
const cutArrayAfterValue = (arr, value) => {
|
|
72
|
+
const index = arr.indexOf(value);
|
|
73
|
+
if (index !== -1) {
|
|
74
|
+
return arr.slice(index + 1);
|
|
75
|
+
}
|
|
76
|
+
return arr;
|
|
77
|
+
};
|
|
78
|
+
const createNestedObject = (arr, lastValue) => {
|
|
79
|
+
let nestedObject = {};
|
|
80
|
+
if (arr.length === 0) {
|
|
81
|
+
return lastValue;
|
|
82
|
+
}
|
|
83
|
+
arr.reduce((obj, value, index) => {
|
|
84
|
+
if (!obj[value]) {
|
|
85
|
+
obj[value] = {};
|
|
86
|
+
}
|
|
87
|
+
if (index === arr.length - 1 && lastValue) {
|
|
88
|
+
obj[value] = lastValue;
|
|
89
|
+
}
|
|
90
|
+
return obj[value];
|
|
91
|
+
}, nestedObject);
|
|
92
|
+
return nestedObject;
|
|
93
|
+
};
|
package/dist/cjs/object.js
CHANGED
|
@@ -64,7 +64,7 @@ const map = (obj, extention, element) => {
|
|
|
64
64
|
};
|
|
65
65
|
const merge = (element, obj, excludeFrom = []) => {
|
|
66
66
|
for (const e in obj) {
|
|
67
|
-
if (excludeFrom.includes(e) || e.
|
|
67
|
+
if (excludeFrom.includes(e) || e.startsWith("__"))
|
|
68
68
|
continue;
|
|
69
69
|
const elementProp = element[e];
|
|
70
70
|
const objProp = obj[e];
|
|
@@ -76,7 +76,7 @@ const merge = (element, obj, excludeFrom = []) => {
|
|
|
76
76
|
};
|
|
77
77
|
const deepMerge = (element, extend, excludeFrom = []) => {
|
|
78
78
|
for (const e in extend) {
|
|
79
|
-
if (excludeFrom.includes(e) || e.
|
|
79
|
+
if (excludeFrom.includes(e) || e.startsWith("__"))
|
|
80
80
|
continue;
|
|
81
81
|
const elementProp = element[e];
|
|
82
82
|
const extendProp = extend[e];
|
|
@@ -91,7 +91,7 @@ const deepMerge = (element, extend, excludeFrom = []) => {
|
|
|
91
91
|
const clone = (obj, excludeFrom = []) => {
|
|
92
92
|
const o = {};
|
|
93
93
|
for (const prop in obj) {
|
|
94
|
-
if (excludeFrom.includes(prop) || prop.
|
|
94
|
+
if (excludeFrom.includes(prop) || prop.startsWith("__"))
|
|
95
95
|
continue;
|
|
96
96
|
o[prop] = obj[prop];
|
|
97
97
|
}
|
|
@@ -103,7 +103,7 @@ const deepCloneExclude = (obj, excludeFrom = []) => {
|
|
|
103
103
|
}
|
|
104
104
|
const o = {};
|
|
105
105
|
for (const k in obj) {
|
|
106
|
-
if (excludeFrom.includes(k) || k.
|
|
106
|
+
if (excludeFrom.includes(k) || k.startsWith("__"))
|
|
107
107
|
continue;
|
|
108
108
|
let v = obj[k];
|
|
109
109
|
if (k === "extend" && (0, import_types.isArray)(v)) {
|
|
@@ -124,7 +124,7 @@ const mergeArrayExclude = (arr, excl = []) => {
|
|
|
124
124
|
const deepClone = (obj, excludeFrom = []) => {
|
|
125
125
|
const o = (0, import_types.isArray)(obj) ? [] : {};
|
|
126
126
|
for (const prop in obj) {
|
|
127
|
-
if (excludeFrom.includes(prop) || prop.
|
|
127
|
+
if (excludeFrom.includes(prop) || prop.startsWith("__"))
|
|
128
128
|
continue;
|
|
129
129
|
let objProp = obj[prop];
|
|
130
130
|
if (prop === "extend" && (0, import_types.isArray)(objProp)) {
|
|
@@ -322,7 +322,7 @@ const overwrite = (element, params, excludeFrom = []) => {
|
|
|
322
322
|
const { ref } = element;
|
|
323
323
|
const changes = {};
|
|
324
324
|
for (const e in params) {
|
|
325
|
-
if (excludeFrom.includes(e) || e.
|
|
325
|
+
if (excludeFrom.includes(e) || e.startsWith("__"))
|
|
326
326
|
continue;
|
|
327
327
|
const elementProp = element[e];
|
|
328
328
|
const paramsProp = params[e];
|
|
@@ -335,7 +335,7 @@ const overwrite = (element, params, excludeFrom = []) => {
|
|
|
335
335
|
};
|
|
336
336
|
const overwriteShallow = (obj, params, excludeFrom = []) => {
|
|
337
337
|
for (const e in params) {
|
|
338
|
-
if (excludeFrom.includes(e) || e.
|
|
338
|
+
if (excludeFrom.includes(e) || e.startsWith("__"))
|
|
339
339
|
continue;
|
|
340
340
|
obj[e] = params[e];
|
|
341
341
|
}
|
|
@@ -343,10 +343,12 @@ const overwriteShallow = (obj, params, excludeFrom = []) => {
|
|
|
343
343
|
};
|
|
344
344
|
const overwriteDeep = (obj, params, excludeFrom = []) => {
|
|
345
345
|
for (const e in params) {
|
|
346
|
-
if (excludeFrom.includes(e) || e.
|
|
346
|
+
if (excludeFrom.includes(e) || e.startsWith("__"))
|
|
347
347
|
continue;
|
|
348
348
|
const objProp = obj[e];
|
|
349
349
|
const paramsProp = params[e];
|
|
350
|
+
if (!obj.hasOwnProperty(e) || e === "__proto__" || e === "constructor")
|
|
351
|
+
continue;
|
|
350
352
|
if ((0, import_types.isObjectLike)(objProp) && (0, import_types.isObjectLike)(paramsProp)) {
|
|
351
353
|
overwriteDeep(objProp, paramsProp);
|
|
352
354
|
} else if (paramsProp !== void 0) {
|
package/object.js
CHANGED
|
@@ -24,7 +24,7 @@ export const map = (obj, extention, element) => {
|
|
|
24
24
|
|
|
25
25
|
export const merge = (element, obj, excludeFrom = []) => {
|
|
26
26
|
for (const e in obj) {
|
|
27
|
-
if (excludeFrom.includes(e) || e.
|
|
27
|
+
if (excludeFrom.includes(e) || e.startsWith('__')) continue
|
|
28
28
|
const elementProp = element[e]
|
|
29
29
|
const objProp = obj[e]
|
|
30
30
|
if (elementProp === undefined) {
|
|
@@ -36,7 +36,7 @@ export const merge = (element, obj, excludeFrom = []) => {
|
|
|
36
36
|
|
|
37
37
|
export const deepMerge = (element, extend, excludeFrom = []) => {
|
|
38
38
|
for (const e in extend) {
|
|
39
|
-
if (excludeFrom.includes(e) || e.
|
|
39
|
+
if (excludeFrom.includes(e) || e.startsWith('__')) continue
|
|
40
40
|
const elementProp = element[e]
|
|
41
41
|
const extendProp = extend[e]
|
|
42
42
|
if (isObjectLike(elementProp) && isObjectLike(extendProp)) {
|
|
@@ -51,7 +51,7 @@ export const deepMerge = (element, extend, excludeFrom = []) => {
|
|
|
51
51
|
export const clone = (obj, excludeFrom = []) => {
|
|
52
52
|
const o = {}
|
|
53
53
|
for (const prop in obj) {
|
|
54
|
-
if (excludeFrom.includes(prop) || prop.
|
|
54
|
+
if (excludeFrom.includes(prop) || prop.startsWith('__')) continue
|
|
55
55
|
o[prop] = obj[prop]
|
|
56
56
|
}
|
|
57
57
|
return o
|
|
@@ -65,7 +65,7 @@ export const deepCloneExclude = (obj, excludeFrom = []) => {
|
|
|
65
65
|
|
|
66
66
|
const o = {}
|
|
67
67
|
for (const k in obj) {
|
|
68
|
-
if (excludeFrom.includes(k) || k.
|
|
68
|
+
if (excludeFrom.includes(k) || k.startsWith('__')) continue
|
|
69
69
|
|
|
70
70
|
let v = obj[k]
|
|
71
71
|
|
|
@@ -94,7 +94,7 @@ export const mergeArrayExclude = (arr, excl = []) => {
|
|
|
94
94
|
export const deepClone = (obj, excludeFrom = []) => {
|
|
95
95
|
const o = isArray(obj) ? [] : {}
|
|
96
96
|
for (const prop in obj) {
|
|
97
|
-
if (excludeFrom.includes(prop) || prop.
|
|
97
|
+
if (excludeFrom.includes(prop) || prop.startsWith('__')) continue
|
|
98
98
|
let objProp = obj[prop]
|
|
99
99
|
if (prop === 'extend' && isArray(objProp)) {
|
|
100
100
|
objProp = mergeArray(objProp)
|
|
@@ -305,7 +305,7 @@ export const overwrite = (element, params, excludeFrom = []) => {
|
|
|
305
305
|
const changes = {}
|
|
306
306
|
|
|
307
307
|
for (const e in params) {
|
|
308
|
-
if (excludeFrom.includes(e) || e.
|
|
308
|
+
if (excludeFrom.includes(e) || e.startsWith('__')) continue
|
|
309
309
|
|
|
310
310
|
const elementProp = element[e]
|
|
311
311
|
const paramsProp = params[e]
|
|
@@ -321,7 +321,7 @@ export const overwrite = (element, params, excludeFrom = []) => {
|
|
|
321
321
|
|
|
322
322
|
export const overwriteShallow = (obj, params, excludeFrom = []) => {
|
|
323
323
|
for (const e in params) {
|
|
324
|
-
if (excludeFrom.includes(e) || e.
|
|
324
|
+
if (excludeFrom.includes(e) || e.startsWith('__')) continue
|
|
325
325
|
obj[e] = params[e]
|
|
326
326
|
}
|
|
327
327
|
return obj
|
|
@@ -332,9 +332,10 @@ export const overwriteShallow = (obj, params, excludeFrom = []) => {
|
|
|
332
332
|
*/
|
|
333
333
|
export const overwriteDeep = (obj, params, excludeFrom = []) => {
|
|
334
334
|
for (const e in params) {
|
|
335
|
-
if (excludeFrom.includes(e) || e.
|
|
335
|
+
if (excludeFrom.includes(e) || e.startsWith('__')) continue
|
|
336
336
|
const objProp = obj[e]
|
|
337
337
|
const paramsProp = params[e]
|
|
338
|
+
if (!obj.hasOwnProperty(e) || e === '__proto__' || e === 'constructor') continue
|
|
338
339
|
if (isObjectLike(objProp) && isObjectLike(paramsProp)) {
|
|
339
340
|
overwriteDeep(objProp, paramsProp)
|
|
340
341
|
} else if (paramsProp !== undefined) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.142",
|
|
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": "
|
|
26
|
+
"gitHead": "5d134dec55390026220f6370a71c82feb6f26aad",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "^7.12.0"
|
|
29
29
|
}
|