From: Ardis Lu Date: Fri, 22 Aug 2025 02:36:54 +0000 (-0700) Subject: Rename `CSVNormalizerRow` to `CSVNormalizerField` X-Git-Tag: v0.1.6~15 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=c685de559382e9707576ba6f86a0a7845fc441de;p=csvio Rename `CSVNormalizerRow` to `CSVNormalizerField` This type is not a row of data, it is a single field. So the name "row" never made sense. --- diff --git a/README.md b/README.md index 1815a70..46ae6cc 100644 --- a/README.md +++ b/README.md @@ -163,9 +163,9 @@ In addition to the core API, optional utilities are provided to address common C - **Fix date and number mangling**: Spreadsheet programs may [automatically cast data types in unexpected ways](https://www.theverge.com/2020/8/6/21355674/human-genes-rename-microsoft-excel-misreading-dates). `CSVNormalizer` will perform various transformations to reverse data type casting that was unlikely to be intentional. - **Flexible column naming**: Column names are normalized to camelCase to prevent issues with subtly inconsistent names (e.g., `Column A`, `column A`, and `ColumnA` are all considered to be the same name). - **Column ordering**: Columns may appear in any order on the input CSV. The columns in the output are re-ordered to match the order in the `CSVNormalizerHeader` array. -- **Stream of objects**: The stream is transformed from an `Array` to an `Array` to provide a better developer experience for subsequent transformations. +- **Stream of objects**: The stream is transformed from an `Array` to an `Array` to provide a better developer experience for subsequent transformations. -`CSVDenormalizer` is a `TransformStream` that will convert an `Array` created by `CSVNormalizer` back into an `Array`, ready for writing to a file. +`CSVDenormalizer` is a `TransformStream` that will convert an `Array` created by `CSVNormalizer` back into an `Array`, ready for writing to a file. ```javascript import { CSVNormalizer, CSVDenormalizer } from '@ardislu/csvio'; diff --git a/src/index.js b/src/index.js index c7c2135..757d271 100644 --- a/src/index.js +++ b/src/index.js @@ -13,6 +13,6 @@ export { ErrorStrategies } from './errorStrategies.js'; /** @typedef {import('./core.js').CSVWriterStatus} CSVWriterStatus */ /** @typedef {import('./normalization.js').CSVNormalizerHeader} CSVNormalizerHeader */ /** @typedef {import('./normalization.js').CSVNormalizerOptions} CSVNormalizerOptions */ -/** @typedef {import('./normalization.js').CSVNormalizerRow} CSVNormalizerRow */ +/** @typedef {import('./normalization.js').CSVNormalizerField} CSVNormalizerField */ /** @typedef {import('./errorStrategies.js').RetryOptions} RetryOptions */ /** @typedef {import('./errorStrategies.js').BackoffOptions} BackoffOptions */ diff --git a/src/normalization.js b/src/normalization.js index 519d3f9..5b2304e 100644 --- a/src/normalization.js +++ b/src/normalization.js @@ -91,7 +91,7 @@ export function expandScientificNotation(str, truncate = false) { /** * The output of `CSVNormalizer`. - * @typedef {Object} CSVNormalizerRow + * @typedef {Object} CSVNormalizerField * @property {string} name The column name after normalization to camelCase. * @property {string} [displayName] The desired column name in the output CSV. * @property {string|number} value The value of the field after attempted data casting. If the original field was empty, this value @@ -143,7 +143,7 @@ export class CSVNormalizer extends TransformStream { } } - /** @type {import('node:stream/web').TransformerTransformCallback,Array>>} */ + /** @type {import('node:stream/web').TransformerTransformCallback,Array>>} */ #transform(chunk, controller) { // Assume first row is headers and use it to prepare the columns object // Note: the headers row is NOT forwarded downstream @@ -162,7 +162,7 @@ export class CSVNormalizer extends TransformStream { return; } - /** @type {Array>} */ + /** @type {Array>} */ const out = []; for (const { name, type, displayName, defaultValue, index } of this.#columns) { let value = chunk[index] ?? ''; @@ -299,14 +299,14 @@ export class CSVNormalizer extends TransformStream { } /** - * A `TransformStream` to transform a `CSVNormalizerRow` 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 { constructor() { let firstRow = true; super({ - /** @type {import('node:stream/web').TransformerTransformCallback,Array>} */ + /** @type {import('node:stream/web').TransformerTransformCallback,Array>} */ transform(chunk, controller) { if (firstRow) { firstRow = false;