FileExtractorclass

new FileExtractor()
Return
FileExtractor
Base extractor for a file in a tree.

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 titletitle 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.

Examples

new FileExtractor().extract(Bun.file("/abs/path/notes.txt"))

Methods

Go

FileExtractor.extract()method

Read a file and build a tree-element from its text content.

extract(file: BunFile): Promise<TreeElement>
Go

FileExtractor.extractProps()method

Build the file element props from the extracted content.

extractProps(name: string, content: string): Partial<TreeElementProps> & { name: string }