aio-class 2.0.2 → 2.0.3
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/index.d.ts +8 -0
- package/index.js +45 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -269,3 +269,11 @@ export declare class AIOColors {
|
|
|
269
269
|
reverse: (c: I_color) => I_color;
|
|
270
270
|
constructor();
|
|
271
271
|
}
|
|
272
|
+
export declare const getGroupedDic: <T>(rows: T[], traverse: (row: T) => {
|
|
273
|
+
groupIds: string[];
|
|
274
|
+
}) => any;
|
|
275
|
+
export declare const getGroupedTree: <T>(rows: T[], getGroups: (row: T, level: number) => {
|
|
276
|
+
groupIds: string[];
|
|
277
|
+
parentRow: any;
|
|
278
|
+
childsField: string;
|
|
279
|
+
}) => any;
|
package/index.js
CHANGED
|
@@ -2016,3 +2016,48 @@ export class AIOColors {
|
|
|
2016
2016
|
this.reverse = (c) => { return this['to_' + this.getType(c)](this.to_array(c).map((o) => 255 - o)); };
|
|
2017
2017
|
}
|
|
2018
2018
|
}
|
|
2019
|
+
export const getGroupedDic = (rows, traverse) => {
|
|
2020
|
+
const res = {};
|
|
2021
|
+
for (let i = 0; i < rows.length; i++) {
|
|
2022
|
+
const row = rows[i];
|
|
2023
|
+
const { groupIds } = traverse(row);
|
|
2024
|
+
let parent = res;
|
|
2025
|
+
for (let j = 0; j < groupIds.length; j++) {
|
|
2026
|
+
const groupId = groupIds[j];
|
|
2027
|
+
const isLeaf = j === groupIds.length - 1;
|
|
2028
|
+
if (!isLeaf) {
|
|
2029
|
+
parent[groupId] = parent[groupId] || {};
|
|
2030
|
+
parent = parent[groupId];
|
|
2031
|
+
}
|
|
2032
|
+
else {
|
|
2033
|
+
parent[groupId] = parent[groupId] || [];
|
|
2034
|
+
parent[groupId].push(row);
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
return res;
|
|
2039
|
+
};
|
|
2040
|
+
export const getGroupedTree = (rows, getGroups) => {
|
|
2041
|
+
const res = [];
|
|
2042
|
+
for (let i = 0; i < rows.length; i++) {
|
|
2043
|
+
const row = rows[i];
|
|
2044
|
+
const { groupIds } = getGroups(row, 0);
|
|
2045
|
+
let parent = res;
|
|
2046
|
+
for (let j = 0; j < groupIds.length; j++) {
|
|
2047
|
+
const groupId = groupIds[j];
|
|
2048
|
+
const parentResult = parent.find((o) => o.groupId === groupId);
|
|
2049
|
+
const { parentRow, childsField } = getGroups(row, j);
|
|
2050
|
+
if (!parentResult) {
|
|
2051
|
+
const _parentRow = Object.assign(Object.assign({}, parentRow), { [childsField]: [] });
|
|
2052
|
+
parent.push(Object.assign(Object.assign({}, _parentRow), { groupId }));
|
|
2053
|
+
parent = _parentRow[childsField];
|
|
2054
|
+
}
|
|
2055
|
+
else {
|
|
2056
|
+
parent = parentResult[childsField];
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
parent.push(row);
|
|
2060
|
+
parent = res;
|
|
2061
|
+
}
|
|
2062
|
+
return res;
|
|
2063
|
+
};
|