/** * CSV Scanner Implementation * * High-performance CSV scanner using indexOf-based batch scanning. * Provides both synchronous and streaming interfaces. * * Key optimizations: * 1. Use indexOf to find delimiter/quote/newline positions in bulk * 2. Use slice to extract field values (avoids char-by-char concatenation) * 3. Minimize function call overhead by inlining hot paths * * @example Basic usage * ```ts * import { createScanner, scanAllRows } from './scanner.js'; * * // One-shot parsing * const rows = scanAllRows('a,b,c\n1,2,3\n'); * * // Or use scanner instance * const scanner = createScanner({ delimiter: '\t' }); * const result = scanner.scanRow('a\tb\tc\n'); * ``` * * @example Streaming usage * ```ts * import { scanRowsAsync } from './scanner.js'; * * async function* readChunks() { * yield 'a,b,c\n'; * yield '1,2,3\n'; * } * * for await (const row of scanRowsAsync(readChunks())) { * console.log(row.fields); * } * ``` */ import type { ScannerConfig, FieldScanResult, RowScanResult, Scanner } from "./types.js"; export type { ScannerConfig, RowScanResult, Scanner } from "./types.js"; export { DEFAULT_SCANNER_CONFIG } from "./types.js"; /** * Scan a quoted field starting at the opening quote. * * Handles: * - Escaped quotes (RFC 4180: "" -> ") * - Backslash escapes when escape !== quote * - CRLF normalization inside quoted fields (CRLF -> LF) * - relaxQuotes mode (allow unescaped quotes mid-field) * * Performance optimization: Uses array to collect segments instead of * string concatenation to avoid O(n²) string building in fields with * many escaped quotes or embedded newlines. * * @param input - Input string * @param start - Position of opening quote * @param config - Scanner configuration * @param isEof - Whether this is the end of input * @returns Field scan result */ export declare function scanQuotedField(input: string, start: number, config: ScannerConfig, isEof: boolean): FieldScanResult; /** * Scan an unquoted field using indexOf for batch searching. * * This is the performance-critical path for most CSV files. * Uses indexOf to find the next delimiter or newline in O(n) time * with optimized native string search. * * @param input - Input string * @param start - Starting position * @param config - Scanner configuration * @param isEof - Whether this is the end of input * @returns Field scan result */ export declare function scanUnquotedField(input: string, start: number, config: ScannerConfig, isEof: boolean): FieldScanResult; /** * Scan a complete row from the input string. * * @param input - Input string * @param start - Starting position * @param config - Scanner configuration * @param isEof - Whether this is the end of input * @param outFields - Optional reusable array for fields (will be cleared) * @param outQuoted - Optional reusable array for quoted flags (will be cleared) * @returns Row scan result with rawStart/rawEnd for zero-copy raw row extraction */ export declare function scanRow(input: string, start: number, config: ScannerConfig, isEof: boolean, outFields?: string[], outQuoted?: boolean[]): RowScanResult; /** * Create a new CSV scanner with the given configuration. * * @param config - Partial scanner configuration (defaults applied) * @returns Scanner instance * * @example Basic usage * ```ts * const scanner = createScanner({ delimiter: "," }); * const result = scanner.scanRow('a,b,c\n'); * console.log(result.fields); // ["a", "b", "c"] * ``` * * @example Streaming usage * ```ts * const scanner = createScanner({ delimiter: "\t" }); * * // Process chunks as they arrive * scanner.feed("name\tage\n"); * scanner.feed("Alice\t30\n"); * * let row; * while ((row = scanner.nextRow()) !== null) { * console.log(row.fields); * } * ``` */ export declare function createScanner(config?: Partial): Scanner; /** * Scan all rows from a complete input string. * * This is a convenience function for parsing complete CSV data in one call. * For large files or streaming data, use the Scanner interface instead. * * @param input - Complete CSV input string * @param config - Scanner configuration * @returns Array of row scan results * * @example * ```ts * const rows = scanAllRows('a,b,c\n1,2,3\n', { delimiter: ',' }); * // rows = [ * // { fields: ['a', 'b', 'c'], quoted: [false, false, false], ... }, * // { fields: ['1', '2', '3'], quoted: [false, false, false], ... } * // ] * ``` */ export declare function scanAllRows(input: string, config?: Partial): RowScanResult[]; /** * Create an async iterator for scanning rows from chunks. * * @param chunks - Async iterable of string chunks * @param config - Scanner configuration * @returns Async iterator of row scan results * * @example * ```ts * const chunks = (async function*() { * yield 'a,b,c\n'; * yield '1,2,3\n'; * })(); * * for await (const row of scanRowsAsync(chunks, { delimiter: ',' })) { * console.log(row.fields); * } * ``` */ export declare function scanRowsAsync(chunks: AsyncIterable, config?: Partial): AsyncGenerator;