]> git.ardis.lu - csvio/commitdiff
Stringify all values passed through
authorArdis Lu <ardisglu@gmail.com>
Mon, 6 Oct 2025 04:42:54 +0000 (21:42 -0700)
committerArdis Lu <ardisglu@gmail.com>
Mon, 6 Oct 2025 04:50:46 +0000 (21:50 -0700)
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
test/normalization.test.js

index 70ce0871d083ffe5dd7607859c34b7934970f163..ac7bc41094dcb58cb6fa0c2bf71a89231461a72e 100644 (file)
@@ -376,7 +376,7 @@ export class CSVNormalizer extends TransformStream {
 }
 
 /**
- * A `TransformStream` to transform a `Array<CSVNormalizerField>` into an array that can be converted to CSV data.
+ * A `TransformStream` to transform a `Array<CSVNormalizerField>` into an `Array<string>` 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()));
       }
     });
   }
index cc2700d252630cdca419f1a3abeb04221c081158..ce7bb725afdb2bb2ce6160a0e83ffe3e16742bff 100644 (file)
@@ -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 () => {
This page took 0.042314 seconds and 4 git commands to generate.