shelving
Version:
Toolkit for using data in JavaScript.
25 lines (24 loc) • 1.36 kB
TypeScript
import { type DirectoryElement } from "../util/element.js";
import { type Matchables } from "../util/regexp.js";
import type { Extractor } from "./Extractor.js";
import { ThroughExtractor } from "./ThroughExtractor.js";
/** Options for an `IndexFileExtractor`. */
export interface IndexFileExtractorOptions {
/**
* Filename patterns treated as the directory's index file. Matched case-insensitively against each child element's `key`.
* - Defaults to README and index files: `["readme.txt", "readme.md", "index.md", "index.ts", "index.tsx"]`.
*/
readonly index?: Matchables;
}
/**
* Through extractor that walks a `DirectoryElement` tree and absorbs each directory's index file into the directory itself.
* - For each directory: finds the first child whose `key` matches any `index` pattern.
* - The matched child's `title`, `description`, `content`, and `children` are folded into the parent directory.
* - The matched child is removed from the parent's children list.
* - Recurses into subdirectories before absorbing — the deepest level happens first.
*/
export declare class IndexFileExtractor<I> extends ThroughExtractor<I, DirectoryElement> {
private readonly _index;
constructor(source: Extractor<I, DirectoryElement>, { index }?: IndexFileExtractorOptions);
extract(input: I): Promise<DirectoryElement>;
}