/** * CSV Row Utilities * * Helper functions for working with different row formats: * - RowHashArray: Array of [key, value] tuples, e.g., [["name", "John"], ["age", "30"]] * - RowMap: Record object format * - RowArray: Simple string[] array format * * Key functions: * - isRowHashArray(): Type guard for RowHashArray detection * - extractRowValues(): Extract values from any row format * - detectRowKeys(): Detect header keys from a row * - deduplicateHeaders(): Handle duplicate column names * - processColumns(): Process column configuration */ import type { ColumnConfig, HeaderArray, RowHashArray } from "../types.js"; export type { HeaderArray, RowHashArray } from "../types.js"; /** * Check if a row is a RowHashArray (array of [key, value] tuples) */ export declare function isRowHashArray(row: unknown): row is RowHashArray; /** * Convert RowHashArray to RowMap * Note: Manual loop is ~4x faster than Object.fromEntries */ export declare function rowHashArrayToMap(row: RowHashArray): Record; /** * Convert RowHashArray to values array (preserving order) */ export declare function rowHashArrayToValues(row: RowHashArray): V[]; /** * Get headers from RowHashArray */ export declare function rowHashArrayToHeaders(row: RowHashArray): string[]; /** * Get value by key from RowHashArray (returns undefined if not found) * More efficient than creating a full map when you need only specific values */ export declare function rowHashArrayGet(row: RowHashArray, key: string): V | undefined; /** * Map RowHashArray values according to header order * Optimized: builds values array in single pass without intermediate object */ export declare function rowHashArrayMapByHeaders(row: RowHashArray, headers: string[]): (V | undefined)[]; /** * Extract values from a row (array, object, or RowHashArray) in consistent order. * This is the unified function for row value extraction used by both * batch (formatCsv) and streaming (CsvFormatterStream) code paths. * * @param row - The row data (array, object, or RowHashArray) * @param keys - Optional key order for object/RowHashArray rows * @returns Array of values in the specified key order (or natural order if no keys) */ export declare function extractRowValues(row: unknown, keys: string[] | null | undefined): unknown[]; /** * Auto-detect keys (headers) from a row based on its type. * Returns empty array for arrays or primitive values. * * @param row - The row data to detect keys from * @returns Array of string keys, or empty array if not applicable */ export declare function detectRowKeys(row: unknown): string[]; /** * Deduplicate headers by appending suffix to duplicates. * Example: ["A", "B", "A", "A"] → ["A", "B", "A_1", "A_2"] * * @param headers - Original header array * @returns New array with unique header names */ export declare function deduplicateHeaders(headers: HeaderArray): HeaderArray; export declare function deduplicateHeadersWithRenames(headers: HeaderArray): { headers: HeaderArray; renamedHeaders: Record | null; }; /** * Process columns configuration to extract keys and headers. * Returns null if columns is empty or undefined. * * This function is used by both formatCsv (batch) and CsvFormatterStream (streaming) * to normalize column configuration into separate key/header arrays. * * @param columns - Column configuration array (string names or ColumnConfig objects) * @returns Object with keys (data access) and headers (output names), or null if empty * * @example * ```ts * processColumns(['name', { key: 'age', header: 'Age (years)' }]) * // { keys: ['name', 'age'], headers: ['name', 'Age (years)'] } * ``` */ export declare function processColumns(columns: (string | ColumnConfig)[] | undefined): { keys: string[]; headers: string[]; } | null; /** * Check if a row should be skipped as empty. * When `shouldSkipEmpty` is "greedy", whitespace-only rows also count as empty. * * @param row - The row to check * @param shouldSkipEmpty - true, false, or "greedy" * @returns true if the row should be skipped */ export declare function isEmptyRow(row: string[], shouldSkipEmpty: boolean | "greedy"): boolean; /** * Check if all values in a row are empty strings. * Used by skipRecordsWithEmptyValues option. * * @param row - The row to check * @returns true if all fields are empty strings */ export declare function hasAllEmptyValues(row: string[]): boolean;