shelving
Version:
Toolkit for using data in JavaScript.
28 lines (27 loc) • 1.73 kB
TypeScript
import type { ImmutableDictionary } from "../util/dictionary.js";
import { type DirectoryElement } from "../util/element.js";
import type { Extractor } from "./Extractor.js";
import { ThroughExtractor } from "./ThroughExtractor.js";
/** Options for a `MergingExtractor`. */
export interface MergingExtractorOptions {
/**
* Templated key pairs that should merge. Each key is a `{base}` template matched against the secondary element's key;
* each value is an ordered list of `{base}` templates for the primary candidates to merge into.
* - The first primary candidate that exists in the same directory wins; remaining candidates are ignored.
* - If no candidate exists the secondary is left in place as its own tree-file element.
* - Defaults to `{ "{base}.md": ["{base}.ts", "{base}.tsx", "{base}.js", "{base}.jsx"] }`.
*/
readonly merges?: ImmutableDictionary<readonly string[]>;
}
/**
* Through extractor that walks a `DirectoryElement` tree and merges sibling tree elements whose keys match a `merges` template pair.
* - Walks every directory recursively, applying the merge at each level.
* - The primary (winning) element keeps its `key`, `source`, and `type`; the secondary's `title`, `description`,
* `content`, and `children` are folded in via `mergeTreeElements()`.
* - A secondary with no matching primary is left in place — pure prose files (e.g. `concepts.md` with no `concepts.ts`) stand alone.
*/
export declare class MergingExtractor<I> extends ThroughExtractor<I, DirectoryElement> {
private readonly _merges;
constructor(source: Extractor<I, DirectoryElement>, { merges }?: MergingExtractorOptions);
extract(input: I): Promise<DirectoryElement>;
}