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

    Type Alias ColumnCountStrategy

    ColumnCountStrategy: "fill" | "sparse" | "keep" | "strict" | "truncate"

    Strategy for handling column count mismatches between header and data rows.

    Choose by goal:

    • 'fill' (default): Keep a consistent shape by padding missing columns with empty string and trimming extra columns (arrays & objects).
    • 'strict': Enforce schema correctness by throwing whenever a row length differs from the header (arrays & objects).
    • 'keep': Preserve ragged rows exactly as parsed (array format only; required when header: []).
    • 'truncate': Drop trailing columns from long rows while leaving short rows untouched (array format only).
    • 'sparse': Allow optional columns by padding with undefined (array format only, explicit header required so the target width is known).

    Format-specific availability:

    • Object output: only 'fill' and 'strict' are valid. Selecting 'keep', 'truncate', or 'sparse' results in a runtime/type error.
    • Array output: all strategies are available.

    Header requirements:

    • Headerless mode (header: []) mandates 'keep'.
    • Inferred headers (header omitted) permit 'fill' (default) or 'keep'; other strategies need a declared header so the target column count is known.
    • 'sparse', 'strict', and 'truncate' all require an explicit header.

    Defaults:

    • Array format → 'fill'
    • Object format → 'fill'
    // Header: ['name', 'age', 'city']
    // Input row: 'Alice,30'
    // outputFormat: 'array'

    // fill → ['Alice', '30', ''] (padded with empty string)
    // sparse → ['Alice', '30', undefined] (padded with undefined)
    // keep → ['Alice', '30'] (short row kept as-is)
    // strict → Error thrown (length mismatch)
    // truncate → ['Alice', '30'] (short row kept as-is, only truncates long rows)
    // Header: ['name', 'age', 'city']
    // Input row: 'Alice,30'
    // outputFormat: 'object'

    // fill → { name: 'Alice', age: '30', city: '' } (all keys present with empty string)
    // strict → Error thrown (length mismatch)
    // keep → Error (object format requires 'fill' or 'strict')
    // truncate → Error (object format requires 'fill' or 'strict')
    // sparse → Error (not supported for object format)