UNPKG

@bakes/dastardly-csv

Version:
52 lines 1.93 kB
import { type DocumentNode, type DataNode, type BaseParseOptions } from '@bakes/dastardly-core'; import { TreeSitterParser, type ParserRuntime, type SyntaxNode } from '@bakes/dastardly-tree-sitter-runtime'; import type { LanguageWrapper } from '@bakes/dastardly-tree-sitter-csv'; export interface CSVParseOptions extends BaseParseOptions { /** * Whether the first row contains headers. * - true: first row is headers, parse as array of objects * - false: no headers, parse as array of arrays * - string[]: use provided headers, parse as array of objects * @default true */ headers?: boolean | string[]; /** * Field delimiter character. * @default ',' */ delimiter?: ',' | '\t' | '|' | string; /** * Whether to infer data types (numbers, booleans, null). * @default false */ inferTypes?: boolean; } export interface CSVParseResult { root: DataNode; } export declare class CSVParser extends TreeSitterParser { private options; constructor(runtime: ParserRuntime, languageWrapper: LanguageWrapper, options?: CSVParseOptions); protected convertDocument(node: SyntaxNode, source: string): DocumentNode; /** * Extract field values from a row node. * When inferTypes is false (literal), returns string[]. * When inferTypes is true (literal), returns (string | DataNode)[]. * When inferTypes is runtime boolean, returns union type. */ private extractFieldValues; /** * Extract value from a field node */ private extractFieldValue; /** * Get the field node at a specific index in a row */ private getFieldNode; } /** * Parse CSV source into an AST * This is primarily for testing - production code should use the format package API */ export declare function parseCSV(source: string, options?: CSVParseOptions): CSVParseResult; //# sourceMappingURL=parser.d.ts.map