shelving
Version:
Toolkit for using data in JavaScript.
26 lines (25 loc) • 1.7 kB
TypeScript
import type { BunFile } from "bun";
import type { FileElement, FileElementProps } from "../util/element.js";
import { Extractor } from "./Extractor.js";
/**
* Base extractor for a file in a tree.
* - Reads the file's content as text and stores it in `content`.
* - Sets `source` to the file's absolute path (`BunFile.name`); throws `RequiredError` if missing or non-absolute.
* - Sets `name` to the basename without extension, preserving case (e.g. `"OptionalSchema"` from `"OptionalSchema.ts"`); URL paths use `name`.
* - Sets `key` to the verbatim filename including extension (e.g. `"OptionalSchema.ts"`). Keys are unique within a directory
* and used by `MergingExtractor` to pair siblings (`{base}.md` + `{base}.ts`) and by `PackageExtractor` to look up sources.
* - Does NOT set `title` — `title` is only set by subclasses that have a confident source for one (e.g. `MarkupExtractor` uses the first `<h1>`). Renderers fall back to `name` when missing.
* - Subclasses (e.g. `MarkupExtractor`, `TypescriptExtractor`) override `extractProps()` to parse the content into richer elements.
*/
export declare class FileExtractor extends Extractor<BunFile, FileElement> {
extract(file: BunFile): Promise<FileElement>;
/**
* Build the file element props from the extracted content.
* - `name` is the basename without extension (e.g. `"array"`) — display-ready, used by menus, cards, and URL paths.
* - Override to parse `text` into richer elements (content/children/description) and to set
* `title` if a confident title is available.
*/
extractProps(name: string, content: string): Partial<FileElementProps> & {
name: string;
};
}