/** * Convert array to single item if only one in the array */ export declare const convertSingleElementArray: (v: T) => T extends ArrayLike ? T[number] : T; /** * @returns iterable or undefined if it is empty */ export declare const undefinedIfEmptyArray: | ArrayLike>(arr: T | undefined) => T | undefined; /** * Predicates to be used with filter */ export declare namespace predicates { const unique: (element: any, i: number, arr: any[]) => boolean; const notNullish: (element: any) => boolean; const notNullishUnique: (element: any, i: number, arr: any[]) => boolean; /** * Identifies items which occur more than N times */ const occursMoreThan: (times: number) => (element: any) => boolean; /** * Identifies items which occur fewer than N times */ const occursFewerThan: (times: number) => (element: any, i: number, arr: any[]) => boolean; } export declare type NestedObject = T & { [K in TChildrenKey]: NestedObject[]; } & { flatten(): NestedObject[]; }; /** * Takes Array of Objects and returns a flattenable array of root objects with nested children (recursively) on the objects * (Use res.flatten() to get a flattened array) * @param objects - Array of objects * @param primaryKey - Primary identifier key * @param parentKey - Key which refers to parent primary key * @param childrenKey - Child array will be assigned to this key */ export declare function nestObjects(objects: T[], primaryKey: keyof T, parentKey: keyof T, childrenKey: TChildrenKey): NestedObject[]; /** * Takes Array of Objects and returns a flattenable array of root objects with nested children (recursively) on the objects * (Use res.flatten() to get a flattened array) * @param objects - Array of objects * @param primaryKey - Primary identifier key * @param parentKey - Key which refers to parent primary key * @param childrenKey - Child array will be assigned to this key * @param preFormatter - Run objects through formatter before nesting */ export declare function nestObjects unknown>(objects: T[], primaryKey: keyof T, parentKey: keyof T, childrenKey: TChildrenKey, preFormatter: TFormatter): TFormatter extends () => infer U ? NestedObject[] : never;