shelving
Version:
Toolkit for using data in JavaScript.
40 lines (39 loc) • 2.19 kB
TypeScript
import type { ImmutableDictionary } from "../util/dictionary.js";
import type { DirectoryElement } from "../util/element.js";
import { type AbsolutePath, type Matchables, type Path } from "../util/index.js";
import { Extractor } from "./Extractor.js";
import { FileExtractor } from "./FileExtractor.js";
/** Options for a directory extractor. */
export interface DirectoryExtractorOptions {
/**
* Extractor dispatch table keyed by file extension (without the leading dot, e.g. `"md"`).
* - Files with no matching extractor are silently skipped.
* - Defaults to `.md` (markdown), `.ts` / `.tsx` (TypeScript), and `.txt` (plain text).
*/
readonly extractors?: ImmutableDictionary<FileExtractor>;
/** Absolute base path used to resolve relative paths passed to `extract()`. */
readonly base?: AbsolutePath;
/**
* Glob patterns for entries to skip — applied to both files and directories.
* - Defaults to test and spec files: `["*.test.ts", "*.test.tsx", "*.spec.ts", "*.spec.tsx"]`.
* - Hidden entries (`.`-prefixed), underscore-prefixed entries, and `node_modules` are always skipped on top of these patterns.
*/
readonly ignore?: Matchables;
}
/**
* Extractor that walks a directory on disk and produces a `DirectoryElement` tree.
* - Recursively descends into subdirectories.
* - Dispatches non-ignored files to a matching `FileExtractor` based on extension; files with no matching extractor are silently skipped.
* - Keys on the produced elements are the verbatim filenames (e.g. `"string.ts"`, `"README.md"`) and directory names (e.g. `"util"`).
* - This is a pure walker: same-key merging and README absorption are intentionally *not* applied here — wrap with `MergingExtractor`
* and/or `IndexFileExtractor` to opt in to those behaviours.
*/
export declare class DirectoryExtractor extends Extractor<Path, DirectoryElement> {
private readonly _extractors;
private readonly _base;
private readonly _ignore;
constructor({ extractors, base, ignore }?: DirectoryExtractorOptions);
extract(source: Path): Promise<DirectoryElement>;
private _extractDirectory;
private _extractChild;
}