/**
 * CSV Parser and Formatter - RFC 4180 compliant
 *
 * A lightweight, cross-platform CSV implementation that works in both
 * Node.js and Browser environments with zero dependencies.
 *
 * High-performance RFC 4180 compliant CSV parser and formatter.
 *
 * @see https://tools.ietf.org/html/rfc4180
 */
/** Header array type (can include undefined to skip columns) */
export type HeaderArray = (string | undefined | null)[];
/** Header transform function */
export type HeaderTransformFunction = (headers: string[]) => HeaderArray;
/** Row types */
export type RowArray = string[];
export type RowMap = Record<string, string>;
export type Row = RowArray | RowMap;
/** Row transform callback */
export type RowTransformCallback<T> = (error?: Error | null, row?: T | null) => void;
/** Row transform function - sync or async */
export type RowTransformFunction<I = Row, O = Row> = ((row: I) => O | null) | ((row: I, callback: RowTransformCallback<O>) => void);
/** Row validate callback */
export type RowValidateCallback = (error?: Error | null, isValid?: boolean, reason?: string) => void;
/** Row validate function - sync or async */
export type RowValidateFunction<T = Row> = ((row: T) => boolean) | ((row: T, callback: RowValidateCallback) => void);
/**
 * CSV parsing options
 */
export interface CsvParseOptions {
    /** Field delimiter (default: ",") */
    delimiter?: string;
    /** Quote character (default: '"'), set to false or null to disable quoting */
    quote?: string | false | null;
    /** Escape character for quotes (default: '"'), set to false or null to disable */
    escape?: string | false | null;
    /** Skip empty lines (default: false) */
    skipEmptyLines?: boolean;
    /** Alias for skipEmptyLines */
    ignoreEmpty?: boolean;
    /** Trim whitespace from both sides of fields (default: false) */
    trim?: boolean;
    /** Left trim whitespace from fields (default: false) */
    ltrim?: boolean;
    /** Right trim whitespace from fields (default: false) */
    rtrim?: boolean;
    /**
     * Header handling:
     * - true: first row is headers, return objects
     * - false: no headers, return arrays
     * - string[]: use these as headers
     * - function: transform first row headers
     */
    headers?: boolean | HeaderArray | HeaderTransformFunction;
    /**
     * If true and headers is string[], discard first row and use provided headers
     */
    renameHeaders?: boolean;
    /** Comment character - lines starting with this are ignored */
    comment?: string;
    /** Maximum number of data rows to parse (excluding header) */
    maxRows?: number;
    /** Number of lines to skip at the beginning (before header detection) */
    skipLines?: number;
    /** Number of data rows to skip (after header detection) */
    skipRows?: number;
    /**
     * Strict column handling:
     * - If true, rows with column count mismatch emit 'data-invalid' event
     * - If false (default), throws error on mismatch (unless discardUnmappedColumns)
     */
    strictColumnHandling?: boolean;
    /**
     * If true, discard columns that exceed header count
     * Only valid when headers are specified
     */
    discardUnmappedColumns?: boolean;
    /**
     * Enable object mode (default: true for Node.js streams)
     * - true: push row objects/arrays
     * - false: push JSON strings
     */
    objectMode?: boolean;
    /**
     * Character encoding for input (default: "utf8")
     * Only used in Node.js streaming context
     */
    encoding?: BufferEncoding;
    /**
     * Synchronous transform function to apply to each row after parsing
     * Return null/undefined to skip the row
     * Works in both Node.js and Browser environments
     *
     * @example
     * // With headers (row is Record<string, string>)
     * transform: (row) => ({ ...row, name: row.name.toUpperCase() })
     *
     * // Without headers (row is string[])
     * transform: (row) => [row[0].toUpperCase(), row[1]]
     */
    transform?: (row: Row) => Row | null | undefined;
    /**
     * Synchronous validate function to check each row
     * Return false to mark row as invalid (will be in invalidRows)
     * Can also return { isValid: boolean, reason?: string }
     * Works in both Node.js and Browser environments
     *
     * @example
     * // With headers
     * validate: (row) => row.name !== ''
     *
     * // With custom reason
     * validate: (row) => ({ isValid: row.age >= 18, reason: 'Must be adult' })
     */
    validate?: (row: Row) => boolean | {
        isValid: boolean;
        reason?: string;
    };
}
/**
 * CSV formatting options
 */
export interface CsvFormatOptions {
    /** Field delimiter (default: ",") */
    delimiter?: string;
    /** Quote character (default: '"'), set to false or null to disable quoting */
    quote?: string | false | null;
    /** Escape character (default: same as quote) */
    escape?: string | false | null;
    /** Row delimiter (default: "\n") */
    rowDelimiter?: string;
    /**
     * Decimal separator used when formatting numbers to CSV (default: ".").
     * For European-style CSV, this is commonly "," (often together with delimiter ";").
     */
    decimalSeparator?: "." | ",";
    /** Always quote all fields (default: false, only quote when necessary) */
    alwaysQuote?: boolean;
    /** Quote specific columns by name or index */
    quoteColumns?: boolean | boolean[] | Record<string, boolean>;
    /** Quote header fields */
    quoteHeaders?: boolean | boolean[] | Record<string, boolean>;
    /**
     * Header handling:
     * - true: auto-detect headers from first object
     * - false/null: no headers
     * - string[]: use these as headers
     */
    headers?: string[] | boolean | null;
    /**
     * Whether to write headers (default: true when headers is provided)
     * Set to false to suppress header row output
     */
    writeHeaders?: boolean;
    /** Include BOM for UTF-8 (default: false) */
    writeBOM?: boolean;
    /** Include final row delimiter (default: true) */
    includeEndRowDelimiter?: boolean;
    /** Write headers even when there's no data (default: false) */
    alwaysWriteHeaders?: boolean;
    /**
     * Transform function to apply to each row before formatting
     * Can be sync (returns row) or async (calls callback)
     */
    transform?: RowTransformFunction<Row, Row>;
    /**
     * Enable object mode (default: true for Node.js streams)
     * - true: accept row objects/arrays directly
     * - false: accept JSON strings
     */
    objectMode?: boolean;
}
/**
 * Parsed CSV result with headers
 */
export interface CsvParseResult<T = string[]> {
    /** Header row (if headers option was true) */
    headers?: string[];
    /** Data rows */
    rows: T[];
    /** Invalid rows (when strictColumnHandling is true) */
    invalidRows?: {
        row: string[];
        reason: string;
    }[];
}
/**
 * Check if a transform function is synchronous (1 argument) vs async (2 arguments)
 */
export declare function isSyncTransform<I, O>(transform: RowTransformFunction<I, O>): transform is (row: I) => O | null;
/**
 * Check if a validate function is synchronous (1 argument) vs async (2 arguments)
 */
export declare function isSyncValidate<T>(validate: RowValidateFunction<T>): validate is (row: T) => boolean;
/**
 * Parse a CSV string into rows of fields
 */
export declare function parseCsv(input: string, options?: CsvParseOptions): string[][] | CsvParseResult<Record<string, string>>;
/**
 * Format data as a CSV string
 */
export declare function formatCsv(data: (string | number | boolean | null | undefined)[][] | Record<string, any>[], options?: CsvFormatOptions): string;
/**
 * Async CSV parser that yields rows one at a time
 */
export declare function parseCsvStream(input: string | AsyncIterable<string>, options?: CsvParseOptions): AsyncGenerator<string[] | Record<string, string>, void, unknown>;
