Skip to content

feat(csv-stringify): support per-column casting - #572

Open
wozhenbang2004 wants to merge 4 commits into
adaltas:masterfrom
wozhenbang2004:feat-stringify-column-cast
Open

wozhenbang2004 wants to merge 4 commits into
adaltas:masterfrom
wozhenbang2004:feat-stringify-column-cast

Conversation

@wozhenbang2004

Copy link
Copy Markdown

Refs #322.

Add an optional cast callback to object column definitions, so columns with the same data type can use different formats without rewriting the input records.

stringify([{ amount: 12, count: 12 }], {
  columns: [{ key: "amount", cast: value => value.toFixed(2) }, "count"]
});
// "12.00,12\n"

The callback receives the original value and existing casting context. It overrides type-based casting for that column's data; headers and columns without a callback keep their current casts. Return values, field options, quoting and errors use the existing casting path. Includes types, tests and a sample.

On Node 24.22.3, the package tests pass with 255 passing and 1 existing pending when excluding the existing api.sync.memory.js sample. That sample exceeds the same 512 MB heap on both the original base and this branch. TypeScript, the package build, and changed-file lint/format checks pass. Test sources and CI are unchanged apart from the added feature tests.

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