From: Ardis Lu Date: Tue, 27 May 2025 05:06:37 +0000 (-0700) Subject: Refine types X-Git-Tag: v0.1.0~11 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=49b2827057404325dbe11959b9b520c23730db14;p=csvio Refine types --- 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))