/** * CSV Parse Configuration * * Defines the ParseConfig type and factory function for creating * normalized parsing configuration from user options. */ import type { CsvParseOptions } from "../types.js"; import { createOnSkipHandler } from "./helpers.js"; import type { ScannerConfig } from "./scanner/index.js"; /** * Resolved parsing configuration (after option normalization) */ export interface ParseConfig { delimiter: string; linebreak: string; /** Pre-compiled regex for line splitting (used in fast mode) */ linebreakRegex: RegExp | string; quote: string; escape: string; quoteEnabled: boolean; trimField: (s: string) => string; /** Whether trimField is an identity function (no actual trimming) - cached for performance */ trimFieldIsIdentity: boolean; shouldSkipEmpty: boolean | "greedy"; skipLines: number; skipRows: number; maxRows?: number; toLine?: number; maxRowBytes?: number; comment?: string; fastMode: boolean; relaxQuotes: boolean; columnLess: "error" | "pad"; columnMore: "error" | "truncate" | "keep"; groupColumnsByName: boolean; skipRecordsWithError: boolean; skipRecordsWithEmptyValues: boolean; infoOption: boolean; rawOption: boolean; dynamicTyping: CsvParseOptions["dynamicTyping"]; castDate: CsvParseOptions["castDate"]; invokeOnSkip: ReturnType; headers: CsvParseOptions["headers"]; } /** * Options for creating ParseConfig. * - For batch parsing: provide `input` for auto-detection and BOM stripping * - For streaming: omit `input` (will use defaults, detection handled separately) */ export interface CreateParseConfigOptions { /** Raw input string (for batch parsing with auto-detection) */ input?: string; /** CSV parse options */ options: CsvParseOptions; /** Override delimiter (for streaming after detection) */ detectedDelimiter?: string; } /** * Result of createParseConfig */ export interface ParseConfigResult { /** Resolved parse configuration */ config: ParseConfig; /** Processed input with BOM stripped and beforeFirstChunk applied (if input was provided) */ processedInput?: string; } /** * Create a normalized ParseConfig from options. * This is the single source of truth for configuration normalization, * used by both sync and streaming parsers. * * @example Batch parsing * ```ts * const { config, processedInput } = createParseConfig({ input: csvString, options }); * ``` * * @example Streaming parsing * ```ts * const { config } = createParseConfig({ options }); * // Later, after delimiter detection: * config.delimiter = detectedDelimiter; * ``` */ export declare function createParseConfig(opts: CreateParseConfigOptions): ParseConfigResult; /** * Resolve options into a normalized config object. * Convenience wrapper around createParseConfig that ensures processedInput is non-null. */ export declare function resolveParseConfig(input: string, options: CsvParseOptions): { config: ParseConfig; processedInput: string; }; /** * Convert ParseConfig to ScannerConfig */ export declare function toScannerConfig(config: ParseConfig): ScannerConfig; /** * Create a trim function based on options */ export declare function makeTrimField(trim: boolean, ltrim: boolean, rtrim: boolean): (s: string) => string;