/** * Options for building a tree from a list of file paths. * @template MetaData - Type of optional meta data attached to each node via addMetaData. */ export type PathListToTreeOptions> = { /** Path to treat as the current item (sets current and isAncestor on nodes). */ currentPath?: string; /** Base URL used when parsing paths to stems (e.g. for index-as-parent). */ baseUrl?: string; /** File extensions to include; defaults include .html and .htm. */ extensions?: string[]; /** Glob patterns for paths to ignore. */ ignoreGlobs?: string[]; /** When true, create virtual parent nodes for missing ancestors; when false, throw. */ createVirtualParent?: boolean; /** * Sort comparator for the path list. * - `'path'` (default): use pathComparator * - function: custom comparator `(a, b) => number` * - `null`: no sorting (preserve original order) */ comparator?: 'path' | ((a: string, b: string) => number) | null; /** Predicate to include or exclude each node; excluded nodes and their descendants are removed. */ filter?: (node: Node) => boolean; /** Callback to compute meta data for each node; applied after filtering. */ addMetaData?: (node: Node) => MetaData; }; /** * A node in the path tree. * @template MetaData - Type of optional meta data when addMetaData is used. */ export type Node> = { /** Original path/URL of the file or directory. */ url: string; /** Normalized stem (path segment used as node key). */ stem: string; /** Depth in the tree (0 for root). */ depth: number; /** True if this node is the current path. */ current: boolean; /** True if this node is a directory ancestor of the current path. Only directory nodes (stem ending with '/') can be ancestors. */ isAncestor: boolean; /** Present when the node was created as a virtual parent (no real file). */ virtual?: true; /** Optional meta data when addMetaData option is provided. */ meta?: MetaData; /** Child nodes. */ children: Node[]; }; /** * Builds a tree from a list of file paths. * Paths are sorted (configurable via comparator option), filtered by extensions and ignoreGlobs, then organized into a tree. * Optional filter and addMetaData are applied in that order. * @template MetaData - Type of meta data when addMetaData option is used. * @param pathList - Array of file paths (e.g. from a file system or URL list). * @param options - Options for sorting, filtering, current path, and meta data. * @returns Root node of the tree (stem '/'). * @throws {Error} When pathList is empty or missing root, or when a parent is missing and createVirtualParent is false. */ export declare function pathListToTree>(pathList: string[], options?: PathListToTreeOptions): Node;