web-csv-toolbox - v0.15.0
    Preparing search index...

    Interface StringCSVLexerOptions<Delimiter, Quotation, TrackLocation>

    Options for creating a StringCSVLexer.

    interface StringCSVLexerOptions<
        Delimiter extends string = DEFAULT_DELIMITER,
        Quotation extends string = DEFAULT_QUOTATION,
        TrackLocation extends boolean = false,
    > {
        delimiter?: Delimiter;
        engine?: EngineConfig;
        maxBufferSize?: number;
        quotation?: Quotation;
        signal?: AbortSignal;
        source?: string;
        trackLocation?: TrackLocation;
    }

    Type Parameters

    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"
    }
    })
    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)
    
    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
    
    source?: string

    Source identifier for error reporting (e.g., filename, description).

    This option allows you to specify a human-readable identifier for the CSV source that will be included in error messages. This is particularly useful when parsing multiple files or streams to help identify which source caused an error.

    Security Note: Do not include sensitive information (API keys, tokens, full URLs) in this field as it may be exposed in error messages and logs.

    parseString(csv, { source: "users.csv" });
    // Error: Field count exceeded at row 5 in "users.csv"
    undefined
    
    trackLocation?: TrackLocation

    Enable location tracking for tokens.

    When enabled, tokens include location with start, end Position objects and rowNumber. This is useful for error reporting but adds overhead.

    Performance impact:

    • false (default): No location tracking, maximum performance
    • true: Full location tracking with Position objects

    When to enable:

    • Custom error handling that needs line/column information
    • Building source maps or editors
    • Debugging CSV parsing issues

    Note: High-level APIs (parseString, etc.) always use trackLocation: false for performance. This option is only available in low-level Lexer APIs.

    false
    
    // No location tracking (default, fastest)
    const lexer = new FlexibleStringCSVLexer();
    for (const token of lexer.lex(csv)) {
    console.log(token); // { type: Field, value: 'foo' }
    }

    // With location tracking
    const lexer = new FlexibleStringCSVLexer({ trackLocation: true });
    for (const token of lexer.lex(csv)) {
    console.log(token);
    // { type: Field, value: 'foo', location: { start: {...}, end: {...}, rowNumber: 1 } }
    }