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'; */
+import { TransformStream } from 'node:stream/web';
+
// User locale's decimal separator
const DECIMAL_SEPARATOR = Intl.NumberFormat().formatToParts(.1).find(p => p.type === 'decimal').value;
* 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.
['a', 'b']
])
.pipeThrough(new CSVNormalizer([
+ // @ts-expect-error
{ name: 'columnA', type: 'abc' },
+ // @ts-expect-error
{ name: 'columnB', type: 'def' }
]))
.pipeThrough(new CSVDenormalizer())
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))