web-csv-toolbox
    Preparing search index...

    Interface ParseOptions<Header, Delimiter, Quotation>

    Parse options for CSV string.

    interface ParseOptions<
        Header extends ReadonlyArray<string> = ReadonlyArray<string>,
        Delimiter extends string = DEFAULT_DELIMITER,
        Quotation extends string = DEFAULT_QUOTATION,
    > {
        delimiter?: Delimiter;
        engine?: EngineConfig;
        header?: Header;
        maxBufferSize?: number;
        maxFieldCount?: number;
        quotation?: Quotation;
        signal?: AbortSignal;
        skipEmptyLines?: boolean;
    }

    Type Parameters

    • Header extends ReadonlyArray<string> = ReadonlyArray<string>
    • Delimiter extends string = DEFAULT_DELIMITER
    • Quotation extends string = DEFAULT_QUOTATION

    Hierarchy (View Summary)

    Index

    Properties

    delimiter?: Delimiter

    CSV field delimiter. If you want to parse TSV, specify '\t'.

    Detail restrictions are as follows:

    • Must not be empty
    • Must be a single character
      • Multi-byte characters are not supported
    • Must not include CR or LF
    • Must not be the same as the quotation
    ','
    
    engine?: EngineConfig

    Engine configuration for CSV parsing.

    parse(csv)
    
    parse(csv, { engine: { worker: true } })
    
    await loadWASM();
    parse(csv, { engine: { worker: true, wasm: true } })
    parse(csv, {
    engine: {
    worker: true,
    workerStrategy: "stream-transfer"
    }
    })
    header?: Header

    CSV header.

    If you specify this option, the first record will be treated as a normal record.

    If you don't specify this option, the first record will be treated as a header.

    undefined
    
    maxBufferSize?: number

    Maximum internal buffer size in characters.

    This option limits the size of the internal buffer used during lexing to prevent memory exhaustion attacks. The buffer size is measured in UTF-16 code units (JavaScript string length). When the buffer exceeds this limit, a RangeError will be thrown.

    Set to Infinity to disable the limit (not recommended for untrusted input).

    10 * 1024 * 1024 (approximately 10MB for ASCII, but may vary for non-ASCII)
    
    maxFieldCount?: number

    Maximum number of fields allowed per record.

    This option limits the number of columns/fields in a CSV record to prevent memory exhaustion attacks. When a record exceeds this limit, a FieldCountLimitError will be thrown.

    Set to Number.POSITIVE_INFINITY to disable the limit (not recommended for untrusted input).

    100000
    
    quotation?: Quotation

    CSV field quotation.

    '"'
    
    signal?: AbortSignal

    The signal to abort the operation.

    If the signal is aborted, the operation will be stopped.

    const controller = new AbortController();

    const csv = "foo,bar\n1,2\n3,4";
    try {
    const result = await parse(csv, { signal: controller.signal });
    } catch (e) {
    if (e instanceof DOMException && e.name === "AbortError") {
    console.log("Aborted");
    }
    }

    // Abort with user action
    document.getElementById("cancel-button")
    .addEventListener("click", () => {
    controller.abort();
    });
    const csv = "foo,bar\n1,2\n3,4";

    try {
    const result = await parse(csv, { signal: AbortSignal.timeout(1000) });
    } catch (e) {
    if (e instanceof DOMException && e.name === "TimeoutError") {
    console.log("Timeout");
    }
    }
    undefined
    
    skipEmptyLines?: boolean

    When true, completely empty lines (with only delimiters or whitespace) will be skipped during parsing.

    false