Skip to content

fix(csv-stringify): preserve header cast context when eof is false - #505

Open
ujjwalnain wants to merge 2 commits into
adaltas:masterfrom
ujjwalnain:fix/stringify-header-context-eof
Open

fix(csv-stringify): preserve header cast context when eof is false#505
ujjwalnain wants to merge 2 commits into
adaltas:masterfrom
ujjwalnain:fix/stringify-header-context-eof

Conversation

@ujjwalnain

@ujjwalnain ujjwalnain commented Sep 10, 2026

Copy link
Copy Markdown

With header: true and eof: false, string cast callbacks receive context.header === false for header cells. A formatter that handles headings separately therefore changes behavior when the final newline is disabled:

import { stringify } from "csv-stringify/sync";

stringify([{ name: "alice" }], {
  header: true,
  eof: false,
  cast: {
    string: (value, context) =>
      context.header ? value.toUpperCase() : value,
  },
});
// Before: "name\nalice"
// After:  "NAME\nalice"

Pass the header flag in both branches of headers(). Parameterize the existing header-context test over both EOF settings and compare exact output, including the trailing delimiter.

Validation on Node 24.19.0:

  • Regression fails on the original code and passes with the fix.
  • npm test --workspace=csv-stringify: TypeScript check passes; 210 passing, 1 existing pending test.
  • ESLint passes for both changed files.
  • Additional sync/callback checks pass for header-only and populated input with both EOF settings.

Pass the header flag when eof is disabled so cast callbacks classify header values correctly.
Check header and data cast context plus exact trailing delimiter behavior. The eof:false case fails before the production fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant