UNPKG

study-kgxx-test3

Version:

ts工具函数

76 lines (75 loc) 2.58 kB
/** * @name arrayToTree * @author 李嘉豪 * @description 数组转为树结构数组 * @param { Array<{ [key: string]: any }> } sourceArray 源数组 * @param { null | 0 } parentValue 父节点属性初始值 * @param { ArrayToTreeOptions } options 配置项 * @returns { Array<{ [key: string]: any }> } 返回一个树形数组或者抛出异常返回空数组 */ export declare function arrayToTree(sourceArray: Array<{ [key: string]: any; }>, parentValue?: null | 0, options?: ArrayToTreeOptions): Array<{ [key: string]: any; }>; /** * @name arrayToTreeWithNoParent * @author 李嘉豪 * @description 数组转为树结构数组 * @param { Array<{ [key: string]: any }> } sourceArray 源数组 * @param { null | 0 | '0'} parentValue 父节点属性初始值 * @param { ArrayToTreeOptions } options 配置项 * @returns { Array<{ [key: string]: any }> } 返回一个树形数组或者抛出异常返回空数组 */ export declare function arrayToTreeWithNoParent(sourceArray: Array<{ [key: string]: any; }>, parentValue?: null | 0 | '0', options?: ArrayToTreeOptions): Array<{ [key: string]: any; }>; /** * @name treeToArray * @author 李嘉豪 * @description 树结构数组转为数组 * @param { Array<{ [key: string]: any }> } sourceArray 源数组 * @param { TreeToArrayOptions } options 配置项 * @returns { Array<{ [key: string]: any } > } 返回一个普通数组或者抛出异常返回空数组 */ export declare function treeToArray(sourceArray: Array<{ [key: string]: any; }>, options?: TreeToArrayOptions): Array<{ [key: string]: any; }>; /** * @name getArrayIntersection * @author 李嘉豪 * @description 获取两个数组的交集 * @param { Array<T> } ary1 数组1 * @param { Array<K> } ary2 数组2 * @returns { Array<T|K> } 返回一个新数组 */ export declare function getArrayIntersection<T extends { [key: string]: any; }, K extends { [key: string]: any; }>(ary1: T[], ary2: K[]): (T | K)[]; /** * @name getArrayUnion * @author 李嘉豪 * @description 获取两个数组的并集 * @param { Array<T> } ary1 数组1 * @param { Array<K> } ary2 数组2 * @param { UnionOptions } options 配置项 * @returns { Array<T | K> } 返回一个新数组 */ export declare function getArrayUnion<T, K>(ary1: T[], ary2: K[], options?: UnionOptions): (T | K)[]; export type ArrayToTreeOptions = { parentKey: string; sonKey: string; childrenKey: string; }; export type TreeToArrayOptions = { childrenKey: string; }; export type UnionOptions = { unique: boolean; };