From da2396428d4e57eb7052f3a93ca99a70ba871ca4 Mon Sep 17 00:00:00 2001 From: axiosleo Date: Wed, 21 Feb 2024 13:00:01 +0800 Subject: [PATCH] type: Add Tree2ArrayOptions interface and related functions to helper namespace --- index.d.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/index.d.ts b/index.d.ts index c3c813f..f237b11 100644 --- a/index.d.ts +++ b/index.d.ts @@ -711,6 +711,31 @@ export namespace helper { function empty(a: any): boolean } + export interface Tree2ArrayOptions { + /** + * The name of the parent node index + * @default 'parent_id' + */ + parent_index?: string; + + /** + * The name of the data index + * @default 'id' + */ + data_index?: string; + + /** + * The name of the child node index + * @default 'child' + */ + child_name?: string; + } + + interface BaseObject { + id: string, + name: string, + } + module obj { function _flatten(obj: ObjectItem, sep: string): ObjectItem; function _flatten(obj: T, sep: string): ObjectItem; @@ -720,6 +745,8 @@ export namespace helper { function _assign(targetObj: T, ...objs: ObjectItem[]): T; function _deep_clone(obj: ObjectItem): ObjectItem; function _deep_clone(obj: T): T; + function _tree2array(tree: any[] | any, options?: Tree2ArrayOptions); + function _array2tree(array: any[], options?: Tree2ArrayOptions); } export interface EmitterConfig {