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;
        header?: Header;
        quotation?: Quotation;
        signal?: AbortSignal;
    }

    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
    ','
    
    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
    
    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