From 49b2827057404325dbe11959b9b520c23730db14 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Mon, 26 May 2025 22:06:37 -0700 Subject: [PATCH] Refine types --- src/core.js | 1 + src/normalization.js | 4 +++- test/normalization.test.js | 10 ++++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core.js b/src/core.js index b193f40..e7454d6 100644 --- a/src/core.js +++ b/src/core.js @@ -1,6 +1,7 @@ import { mkdir, open } from 'node:fs/promises'; import { dirname, basename, normalize } from 'node:path'; import { fileURLToPath } from 'node:url'; +import { ReadableStream, WritableStream, TransformStream } from 'node:stream/web'; /** @import { PathLike } from 'node:fs'; */ /** @import { FileHandle } from 'node:fs/promises'; */ diff --git a/src/normalization.js b/src/normalization.js index 9092d0b..f142843 100644 --- a/src/normalization.js +++ b/src/normalization.js @@ -1,3 +1,5 @@ +import { TransformStream } from 'node:stream/web'; + // User locale's decimal separator const DECIMAL_SEPARATOR = Intl.NumberFormat().formatToParts(.1).find(p => p.type === 'decimal').value; @@ -23,7 +25,7 @@ export function toCamelCase(str) { * Convert scientific notation ("E" notation) to normal form. * * @param {string} str A string representing a number expressed using scientific notation (e.g., `"1E+18"`). - * @param {boolean} truncate If `true`, decimals will be truncated in the expanded string. Defaults to `false`. + * @param {boolean} [truncate=false] If `true`, decimals will be truncated in the expanded string. Defaults to `false`. * @returns {string} A string representing the normal form of the number (e.g., `"1000000000000000000"`). * @throws {TypeError} If `str` is not a `string`, a `TypeError` will be thrown. * @throws {SyntaxError} If `str` is not valid scientific notation, a `SyntaxError` will be thrown. diff --git a/test/normalization.test.js b/test/normalization.test.js index 92b8fe3..4ca8e49 100644 --- a/test/normalization.test.js +++ b/test/normalization.test.js @@ -265,7 +265,9 @@ suite('CSVNormalizer', { concurrency: true }, () => { ['a', 'b'] ]) .pipeThrough(new CSVNormalizer([ + // @ts-expect-error { name: 'columnA', type: 'abc' }, + // @ts-expect-error { name: 'columnB', type: 'def' } ])) .pipeThrough(new CSVDenormalizer()) @@ -279,10 +281,10 @@ suite('CSVNormalizer', { concurrency: true }, () => { suite('CSVNormalizer and CSVDenormalizer end-to-end', { concurrency: true }, () => { test('can normalize', { concurrency: true }, async () => { const headers = [ - { name: 'stringCol', displayName: 'String Column', type: 'string', defaultValue: 'N/A' }, - { name: 'numberCol', displayName: 'Number Column', type: 'number' }, - { name: 'bigintCol', displayName: 'BigInt Column', type: 'bigint' }, - { name: 'dateCol', displayName: 'Date Column', type: 'date' } + /** @type {const} */({ name: 'stringCol', displayName: 'String Column', type: 'string', defaultValue: 'N/A' }), + /** @type {const} */({ name: 'numberCol', displayName: 'Number Column', type: 'number' }), + /** @type {const} */({ name: 'bigintCol', displayName: 'BigInt Column', type: 'bigint' }), + /** @type {const} */({ name: 'dateCol', displayName: 'Date Column', type: 'date' }) ] await new CSVReader('./test/data/normalization.csv') .pipeThrough(new CSVNormalizer(headers)) -- 2.47.3