UNPKG

@bakes/dastardly-csv

Version:
48 lines 1.74 kB
/** * Quote strategy for CSV fields. */ export type QuoteStrategy = 'needed' | 'all' | 'nonnumeric' | 'none'; /** * Escape a field value for CSV output. * If the field contains the delimiter, quotes, or newlines, it will be quoted. * Quotes within the field are doubled per RFC 4180. * * @param value - The field value to escape * @param delimiter - The delimiter character (e.g., ',', '\t', '|') * @returns Escaped field value (quoted if necessary) */ export declare function escapeField(value: string, delimiter: string): string; /** * Unescape a CSV field value. * Removes surrounding quotes and converts doubled quotes to single quotes. * * @param value - The field value to unescape * @returns Unescaped field value */ export declare function unescapeField(value: string): string; /** * Determine if a field value needs quoting based on the quote strategy. * * @param value - The field value * @param delimiter - The delimiter character * @param quoting - The quote strategy * @returns True if the field should be quoted */ export declare function needsQuoting(value: string, delimiter: string, quoting: QuoteStrategy): boolean; /** * Parse a CSV number from text. * Handles integers, floats, exponential notation, and negative zero. * * @param text - The number text to parse * @returns Parsed number value */ export declare function parseCSVNumber(text: string): number; /** * Normalize line endings in text to the specified style. * * @param text - The text to normalize * @param style - The line ending style ('crlf' or 'lf') * @returns Text with normalized line endings */ export declare function normalizeLineEnding(text: string, style: 'crlf' | 'lf'): string; //# sourceMappingURL=utils.d.ts.map