staticql
Version:
Type-safe query engine for static content including Markdown, YAML, JSON, and more.
49 lines (48 loc) • 1.45 kB
TypeScript
/**
* Union type for parsed content.
*/
export type ParsedData = unknown;
/**
* Options for all parsers.
*/
/**
* Parser function type.
* Accepts ParserOptions and returns parsed data (sync or async).
*/
export type Parser = (options: ParserOptions) => any;
/**
* Options for all parsers.
*/
export interface ParserOptions {
/**
* Raw file content as a string or binary buffer.
*/
rawContent: string | Uint8Array;
}
/**
* Built-in parser registry. Keys are format types.
*/
export declare const defaultParsers: Record<string, Parser>;
/**
* Register or override a parser for a given type.
*/
export declare function registerParser(type: string, parser: Parser): void;
/**
* parseByType: Delegates parsing based on declared content type.
*
* Supports:
* - `"markdown"` → parses frontmatter and body
* - `"yaml"` → parses indentation-based YAML
* - `"json"` → parses standard JSON
*
* @param type - The declared type of the content (`markdown`, `yaml`, or `json`)
* @param options - Contains the raw content to parse
* @returns The parsed result as a plain object (or array)
* @throws If the type is not supported or parsing fails
*/
/**
* parseByType: Delegates parsing based on declared content type, using registered parsers.
*
* You can inject or override parsers via `parserRegistry` before invoking.
*/
export declare function parseByType(type: string, options: ParserOptions): Promise<any>;