@domql/utils 2.3.138 → 2.3.141
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/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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.141",
|
|
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": "ba9451d23df608f67ee1fd24de442cd558387202",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/core": "^7.12.0"
|
|
29
29
|
}
|