@rnaga/wp-node
Version:
👉 **[View Full Documentation at rnaga.github.io/wp-node →](https://rnaga.github.io/wp-node/)**
21 lines • 1.63 kB
TypeScript
import type * as types from "../types";
type Item<T = "terms" | "posts" | "comments", Extended = any> = T extends "terms" ? Pick<types.Tables["terms"], "term_id"> & {
parent: number;
} & Extended : T extends "comments" ? Pick<types.Tables["comments"], "comment_ID" | "comment_parent"> & Partial<types.Tables["comments"]> & Extended : Pick<types.Tables["posts"], "ID" | "post_parent"> & Extended;
type Hierarchy<T> = Array<T & {
depth: number;
children: Hierarchy<T>;
}>;
type Flat<T> = Array<T & {
depth: number;
}>;
declare const to: <Extended, T extends "terms" | "posts" | "comments", I extends Item<T, Extended> = Item<T, Extended>>(table: T, items: I[]) => Hierarchy<I>;
export declare const comments: <TComments extends Item<"comments", types.Tables["comments"]>>(comments: TComments[]) => Hierarchy<Pick<types.WpComments, "comment_ID" | "comment_parent"> & Partial<types.WpComments> & TComments>;
export declare const posts: <TPosts extends Item<"posts", types.Tables["posts"]>>(posts: TPosts[]) => Hierarchy<Pick<types.WpPosts, "ID" | "post_parent"> & TPosts>;
export declare const terms: <TTerms extends Item<"terms", Partial<types.Tables["terms"]>>>(terms: TTerms[]) => Hierarchy<Pick<types.WpTerms, "term_id"> & {
parent: number;
} & TTerms>;
export declare const flat: <T extends Parameters<typeof to>[1]>(table: Parameters<typeof to>[0], items: T) => Flat<T[number]>;
export declare const map: <T extends Parameters<typeof to>[1], R>(table: Parameters<typeof to>[0], items: T, cb: (item: Hierarchy<T[number]>[number], index: number) => R) => R[];
export {};
//# sourceMappingURL=hierarchy.d.ts.map