From: Ardis Lu Date: Sat, 18 Jan 2025 07:12:13 +0000 (-0800) Subject: Split out TransformationFunction callback function signature X-Git-Tag: v0.1.0~121 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=9e0a58b7a45970679635fd136d824d8e3c3021d3;p=csvio Split out TransformationFunction callback function signature --- diff --git a/src/core.js b/src/core.js index 63e9888..e7d7978 100644 --- a/src/core.js +++ b/src/core.js @@ -127,6 +127,13 @@ export function createCSVReadableStream(path) { })); } +/** + * A function to process a row of CSV data from `createCSVReadableStream`. + * @callback TransformationFunction + * @param {Array|string} row A row of input CSV data. + * @returns {Array>|Array|string|null} A row or rows of output CSV data, or null to skip a row. + */ + /** * Options to configure `createCSVTransformStream`. * @typedef {Object} CreateCSVTransformStreamOptions @@ -138,7 +145,7 @@ export function createCSVReadableStream(path) { * using `JSON.parse()` before being sent to `fn()`. The default value is `false`. * @property {boolean} [rawOutput=false] Set to `true` to send the raw return value of `fn()` to the next stream. Otherwise, the return value of * `fn()` will be serialized using `JSON.stringify()` before being sent to the next stream. The default value is `false`. - * @property {null|function(Array|string,Error,function(Array|string):Array>|Array|string|null):Array>|Array|string|null} [onError=null] + * @property {null|function(Array|string,Error,TransformationFunction):Array>|Array|string|null} [onError=null] * Set to a function to catch errors thrown by the transformation function. The CSV row, the error that was thrown, and the transformation function * itself will be passed to the `onError` function. The default value is `null` (errors will not be caught). */ @@ -146,7 +153,7 @@ export function createCSVReadableStream(path) { /** * Create a new [TransformStream](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream) to process CSV data. * - * @param {function(Array|string):Array>|Array|string|null} fn A function to process a row of CSV data from `createCSVReadableStream`. + * @param {TransformationFunction} fn A function to process a row of CSV data from `createCSVReadableStream`. * * If `options.rawInput` is `false` (default), the input will be a `Array` representing the CSV row. If `options.rawInput` is `true`, * the input will be a JSON `string` representing the CSV row.