From 46a93261a3ddeee4ef12b5bc786dff2cdb14c9c8 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sun, 5 Oct 2025 21:42:54 -0700 Subject: [PATCH] Stringify all values passed through This change makes `CSVDenormalizer` behave consistently with its current type definition and aligns expected behavior (if `CSVNormalizer` takes strings and gives native objects, then `CSVDenormalizer` should take native objects and give strings). --- src/normalization.js | 4 ++-- test/normalization.test.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/normalization.js b/src/normalization.js index 70ce087..ac7bc41 100644 --- a/src/normalization.js +++ b/src/normalization.js @@ -376,7 +376,7 @@ export class CSVNormalizer extends TransformStream { } /** - * A `TransformStream` to transform a `Array` into an array that can be converted to CSV data. + * A `TransformStream` to transform a `Array` into an `Array` that can be converted to CSV data. * @extends TransformStream */ export class CSVDenormalizer extends TransformStream { @@ -389,7 +389,7 @@ export class CSVDenormalizer extends TransformStream { firstRow = false; controller.enqueue(chunk.map(f => f?.displayName ?? f.name)); } - controller.enqueue(chunk.map(f => f.value instanceof Date ? f.value.toISOString() : f.value)); + controller.enqueue(chunk.map(f => f.value instanceof Date ? f.value.toISOString() : f.value.toString())); } }); } diff --git a/test/normalization.test.js b/test/normalization.test.js index cc2700d..ce7bb72 100644 --- a/test/normalization.test.js +++ b/test/normalization.test.js @@ -556,7 +556,7 @@ suite('CSVNormalizer', { concurrency: true }, () => { .pipeThrough(new CSVDenormalizer()) .pipeTo(csvStreamEqualWritable([ ['columnA', 'columnB'], - [123, 456] + ['123', '456'] ])); }); test('can pass through BigInt', { concurrency: true }, async () => { @@ -571,7 +571,7 @@ suite('CSVNormalizer', { concurrency: true }, () => { .pipeThrough(new CSVDenormalizer()) .pipeTo(csvStreamEqualWritable([ ['columnA', 'columnB'], - [123n, 456n] + ['123', '456'] ])); }); test('can pass through date', { concurrency: true }, async () => { @@ -658,9 +658,9 @@ suite('CSVNormalizer and CSVDenormalizer end-to-end', { concurrency: true }, () .pipeThrough(new CSVDenormalizer()) .pipeTo(csvStreamEqualWritable([ ['String Column', 'Number Column', 'BigInt Column', 'Date Column'], - ['abc 👨‍👩‍👧‍👦', 123456789.123456, 1000000000000000000n, '2024-01-01T00:00:00.000Z'], - [', " 🏴‍☠️', 1000, -1234567890000000000000000n, '2024-06-01T00:00:00.000Z'], - ['N/A', 123100, 1000000000000000000n, '2024-12-31T08:00:00.000Z'] + ['abc 👨‍👩‍👧‍👦', '123456789.123456', '1000000000000000000', '2024-01-01T00:00:00.000Z'], + [', " 🏴‍☠️', '1000', '-1234567890000000000000000', '2024-06-01T00:00:00.000Z'], + ['N/A', '123100', '1000000000000000000', '2024-12-31T08:00:00.000Z'] ])); }); test('can normalize with transformation', { concurrency: true }, async () => { -- 2.47.3