import { DEFAULT_DELIMITER, DEFAULT_QUOTATION } from '../../../core/constants'; import { CSVRecord, InferCSVRecord, ParseOptions, PickCSVHeader } from '../../../core/types'; /** * Parse CSV string to records. * * @category Middle-level API * @param csv CSV string to parse * @param options Parsing options. See {@link ParseOptions}. * @returns Async iterable iterator of records. * * If you want array of records, use {@link parseString.toArray} function. * * @remarks * **Performance Characteristics:** * - **Memory usage**: O(1) - constant per record (streaming approach) * - **Suitable for**: Files of any size * - **Recommended for**: Large CSV strings (> 10MB) or memory-constrained environments * * **Execution Strategies:** * Control how parsing is executed using the `engine` option: * - **Main thread** (default): `engine: { worker: false }` - No overhead, good for small files * - **Worker thread**: `engine: { worker: true }` - Offloads parsing, good for large files * - **WebAssembly**: `engine: { wasm: true }` - Fast parsing, limited to UTF-8 and double-quotes * - **Combined**: `engine: { worker: true, wasm: true }` - Worker + WASM for maximum performance * * Use {@link EnginePresets} for convenient configurations: * ```ts * import { parseString, EnginePresets } from 'web-csv-toolbox'; * * // Use UI responsiveness + parse speed optimized execution method * for await (const record of parseString(csv, { * engine: EnginePresets.responsiveFast() * })) { * console.log(record); * } * ``` * * @example Parsing CSV files from strings * * ```ts * import { parseString } from 'web-csv-toolbox'; * * const csv = `name,age * Alice,42 * Bob,69`; * * for await (const record of parseString(csv)) { * console.log(record); * } * // Prints: * // { name: 'Alice', age: '42' } * // { name: 'Bob', age: '69' } * ``` * * @example Using worker execution for better performance * ```ts * import { parseString } from 'web-csv-toolbox'; * * // Offload parsing to a worker thread * for await (const record of parseString(largeCSV, { * engine: { worker: true } * })) { * console.log(record); * } * ``` */ export declare function parseString(csv: CSVSource): AsyncIterableIterator, "object">>; export declare function parseString>(csv: string): AsyncIterableIterator>; export declare function parseString, const Options extends ParseOptions
= ParseOptions
>(csv: string, options: Options): AsyncIterableIterator>; export declare function parseString = PickCSVHeader, const Options extends ParseOptions = ParseOptions>(csv: CSVSource, options?: Options): AsyncIterableIterator>; export declare function parseString(csv: string, options?: ParseOptions): AsyncIterableIterator>; export declare namespace parseString { /** * Parse CSV string to records. * * @returns Array of records * * @example * ```ts * import { parseString } from 'web-csv-toolbox'; * * const csv = `name,age * Alice,42 * Bob,69`; * * const records = await parseString.toArray(csv); * console.log(records); * // Prints: * // [ { name: 'Alice', age: '42' }, { name: 'Bob', age: '69' } ] * ``` */ function toArray
, Options extends ParseOptions
= ParseOptions
>(csv: string, options?: Options): Promise[]>; /** * Parse CSV string to records. * * @returns Array of records * * @example * * ```ts * import { parseString } from 'web-csv-toolbox'; * * const csv = `name,age * Alice,42 * Bob,69`; * * const records = parseString.toArraySync(csv); * console.log(records); * // Prints: * // [ { name: 'Alice', age: '42' }, { name: 'Bob', age: '69' } ] * ``` */ function toArraySync
, Options extends ParseOptions
= ParseOptions
>(csv: string, options?: Options): InferCSVRecord[]; /** * Parse CSV string to records. * * @returns Async iterable iterator of records * * @example * ```ts * import { parseString } from 'web-csv-toolbox'; * * const csv = `name,age * Alice,42 * Bob,69`; * * for (const record of parseString.toIterableIterator(csv)) { * console.log(record); * } * // Prints: * // { name: 'Alice', age: '42' } * // { name: 'Bob', age: '69' } * ``` */ function toIterableIterator
, Options extends ParseOptions
= ParseOptions
>(csv: string, options?: Options): IterableIterator>; /** * Parse CSV string to records. * * @returns Readable stream of records * * @example * ```ts * import { parseString } from 'web-csv-toolbox'; * * const csv = `name,age * Alice,42 * Bob,69`; * * await parseString.toStream(csv) * .pipeTo( * new WritableStream({ * write(record) { * console.log(record); * }, * }), * ); * // Prints: * // { name: 'Alice', age: '42' } * // { name: 'Bob', age: '69' } * ``` */ function toStream
, Options extends ParseOptions
= ParseOptions
>(csv: string, options?: Options): ReadableStream>; }