/** * CSV Detection Utilities * * Auto-detection of CSV characteristics: * - Delimiter detection (comma, tab, semicolon, pipe, etc.) * - Line ending detection (LF, CRLF, CR) * - Quote character normalization * * This module is part of the csv/utils subsystem: * - detect.ts: Auto-detection of CSV format * - row.ts: Row format conversions (RowHashArray, headers) * - dynamic-typing.ts: Type coercion (string -> number/boolean/date) * - number.ts: Number parsing utilities * - generate.ts: Test data generation */ /** * Escape special regex characters */ export declare function escapeRegex(str: string): string; /** * Normalize quote option to { enabled, char } form. * Centralizes the quote/false/null handling logic. */ export declare function normalizeQuoteOption(option: string | false | null | undefined): { enabled: boolean; char: string; }; /** * Normalize escape option to { enabled, char } form. * Consistent with normalizeQuoteOption API design. * * @param escapeOption - User's escape option (string, false, null, or undefined) * @param quoteChar - The quote character (used as default when escape is undefined) * @returns { enabled: boolean, char: string } * - enabled=false, char="" when explicitly disabled (false/null) * - enabled=true, char=quoteChar when undefined (default behavior) * - enabled=true, char=escapeOption when string provided */ export declare function normalizeEscapeOption(escapeOption: string | false | null | undefined, quoteChar: string): { enabled: boolean; char: string; }; /** * Strip UTF-8 BOM (Byte Order Mark) from start of string if present. * Excel exports UTF-8 CSV files with BOM (\ufeff). * * @param input - String to process * @returns String without BOM */ export declare function stripBom(input: string): string; /** * Check if a string starts with a formula escape character. * Used for CSV injection prevention. */ export declare function startsWithFormulaChar(str: string): boolean; /** * Detect the line terminator used in a string. * Uses quote-aware detection to avoid detecting newlines inside quoted fields. * * @param input - String to analyze * @param quote - Quote character (default: '"') * @returns Detected line terminator or '\n' as default * * @example * detectLinebreak('a,b\r\nc,d') // '\r\n' * detectLinebreak('a,b\nc,d') // '\n' * detectLinebreak('a,b\rc,d') // '\r' * detectLinebreak('a,b,c') // '\n' (default) * detectLinebreak('"a\nb",c\r\nd') // '\r\n' (ignores newline in quotes) */ export declare function detectLinebreak(input: string, quote?: string): string; /** * Auto-detect the delimiter used in a CSV string * * Algorithm: * 1. Sample the first few lines (up to 10) for analysis * 2. For each candidate delimiter: * - Count occurrences per line (respecting quotes) * - Check consistency: all lines should have the same count * - Higher count = more fields = better delimiter candidate * 3. Choose the delimiter with highest consistent field count * * Tie-breaking rules (in priority order): * 1. Lowest delta (variance) wins - more consistent field counts across lines * 2. On delta tie, highest avgFieldCount wins - more fields per row * 3. On complete tie, array order wins - first delimiter in delimitersToGuess * (default order: comma, semicolon, tab, pipe) * * @param input - CSV string to analyze * @param quote - Quote character (default: '"') * @param delimitersToGuess - Custom list of delimiters to try (default: [",", ";", "\t", "|"]) * @returns Detected delimiter or first delimiter in list * * @example * detectDelimiter('a,b,c\n1,2,3') // ',' * detectDelimiter('a;b;c\n1;2;3') // ';' * detectDelimiter('a\tb\tc\n1\t2\t3') // '\t' * detectDelimiter('a:b:c\n1:2:3', '"', [':']) // ':' */ export declare function detectDelimiter(input: string, quote?: string, delimitersToGuess?: string[], comment?: string, skipEmptyLines?: boolean | "greedy"): string;