vincentlu
2025-02-05 9d79b8c8d34077ebf782a7b61d54ee4e1debdba1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
export const extractNavMenus = (data) => {
    if (!data) {
        return;
    }
    const navMenus = [];
    const traverse = (nodes) => {
        nodes.forEach((node) => {
            if (!node.children) {
                navMenus.push(node);
            } else {
                traverse(node.children);
            }
        });
    };
    traverse(data);
    return navMenus;
};
 
export const integrateParams = (_params) => {
    const { pagination, sort, filter, ...other } = _params;
    return {
        current: pagination?.page,
        pageSize: pagination?.perPage,
        orderBy: sort?.field + ' ' + sort?.order,
        ...filter,
        ...other
    }
}
 
export const camelToPascalWithSpaces = (camelCaseString) => {
    if (typeof camelCaseString !== 'string') {
        return '';
    }
    if (camelCaseString.trim() === '') {
        return '';
    }
    return camelCaseString
        .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
        .replace(/^\w/, (c) => c.toUpperCase());
}
 
export const flattenTree = (nodes, depth = 0) => {
    let result = [];
    nodes.forEach(node => {
        result.push({ ...node, depth });
        if (node.children && node.children.length > 0) {
            result = result.concat(flattenTree(node.children, depth + 1));
        }
    });
    return result;
};