@unchainedshop/core-assortments 4.8.4 → 4.8.9
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.
|
@@ -5,19 +5,28 @@ export const fillToSameLengthArray = (a, b) => {
|
|
|
5
5
|
return [fillUp(a, length), fillUp(b, length)];
|
|
6
6
|
};
|
|
7
7
|
export const divideTreeByLevels = (array, level = 0) => {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const result = [];
|
|
9
|
+
const stack = [{ array, level }];
|
|
10
|
+
while (stack.length > 0) {
|
|
11
|
+
const { array: current, level: currentLevel } = stack.pop();
|
|
12
|
+
const items = [];
|
|
13
|
+
const children = [];
|
|
14
|
+
for (const item of current) {
|
|
15
|
+
if (typeof item === 'object') {
|
|
16
|
+
children.push(item);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
items.push(item);
|
|
20
|
+
}
|
|
11
21
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const nextLevels = array.reduce((acc, item) => {
|
|
15
|
-
if (typeof item === 'object') {
|
|
16
|
-
return [...acc, ...divideTreeByLevels(item, level + 1)];
|
|
22
|
+
if (items.length) {
|
|
23
|
+
result.push({ level: currentLevel, items });
|
|
17
24
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
26
|
+
stack.push({ array: children[i], level: currentLevel + 1 });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
21
30
|
};
|
|
22
31
|
export const concatItemsByLevels = (levelArray) => {
|
|
23
32
|
return Object.values(levelArray.reduce((acc, { level, items }) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-assortments",
|
|
3
3
|
"description": "Assortment and category management module for the Unchained Engine",
|
|
4
|
-
"version": "4.8.
|
|
4
|
+
"version": "4.8.9",
|
|
5
5
|
"main": "lib/assortments-index.js",
|
|
6
6
|
"types": "lib/assortments-index.d.ts",
|
|
7
7
|
"type": "module",
|