]> git.ardis.lu - csvio/commitdiff
Add explicit types
authorArdis Lu <ardisglu@gmail.com>
Mon, 27 Oct 2025 06:08:16 +0000 (23:08 -0700)
committerArdis Lu <ardisglu@gmail.com>
Mon, 27 Oct 2025 06:08:16 +0000 (23:08 -0700)
examples/ex1_1.js
examples/ex1_2.js
examples/ex1_5.js
examples/ex1_7.js
examples/ex1_9.js
examples/ex4_2.js

index 11389cd986bfb09a4d58bcda9f58344b19d6da9e..e376ace15532cb686347786c81e4134ca7d2eef1 100644 (file)
@@ -9,7 +9,9 @@
 // - The expected output of the transformation function is another array representing 1 row of the output CSV.
 
 import { CSVReader, CSVTransformer, CSVWriter } from '../src/index.js';
+/** @import { TransformationFunction } from '../src/index.js'; */
 
+/** @type {TransformationFunction} */
 function timesTwo(row) {
   return [Number(row[0]) * 2, Number(row[1]) * 2];
 }
index 68ac8640fa85e689d408c971af1ca1a3cb61713f..13b8f5190a41af6c94f7c02d471fd80cbfa06bd1 100644 (file)
@@ -7,7 +7,9 @@
 // - Setting `handleHeaders` to an array is the simplest way to rename headers, delete headers, or add new headers.
 
 import { CSVReader, CSVTransformer, CSVWriter } from '../src/index.js';
+/** @import { TransformationFunction } from '../src/index.js'; */
 
+/** @type {TransformationFunction} */
 function sum(row) {
   return [...row, Number(row[0]) + Number(row[1])];
 }
index 0d49b5258b535e90a20b165f483b54a63829ee89..4796d69ff7030303d372bd291ed0b04163240bd5 100644 (file)
@@ -8,13 +8,16 @@
 // or other arbitrary logic is required to determine the output header names.
 
 import { CSVReader, CSVTransformer, CSVWriter } from '../src/index.js';
+/** @import { TransformationFunction } from '../src/index.js'; */
 
 // It is useful to split the header transformation into a separate function because the logic for the header
 // is likely different from the rest of the CSV.
+/** @type {TransformationFunction} */
 function handleHeaders(headers) {
   return [...headers, 'min', 'max', 'mean']; // Duplicate input headers as the first headers in the output
 }
 
+/** @type {TransformationFunction} */
 function calculate(row) {
   const numbers = row.map(Number);
   const min = Math.min(...numbers);
index abfadd3ccd97cfb1b4382e49f4b0ea05e39595f6..1ba78fb9c0e738e1a2be2041434159a96a6d40a7 100644 (file)
@@ -7,8 +7,10 @@
 // Aborting throws an error, so you must also add a `.catch()` to handle the abort.
 
 import { CSVReader, CSVTransformer, CSVWriter } from '../src/index.js';
+/** @import { TransformationFunction } from '../src/index.js'; */
 
 const controller = new AbortController();
+/** @type {TransformationFunction} */
 function identityWithAbort(row) {
   if (row[0] === 'abort') { // Arbitrary logic for aborting the transformation
     controller.abort();
index e4c10a9c448ee36cb7976d90f42b2cf6e51a716b..ed41521fddcb0a93f8583f50d6fdd713cc787377 100644 (file)
@@ -9,12 +9,15 @@
 
 import { createWriteStream } from 'node:fs';
 import { Writable } from 'node:stream';
+import { DecompressionStream, TextDecoderStream, CompressionStream } from 'node:stream/web';
 
 import { CSVReader, CSVTransformer, CSVWriter } from '../src/index.js';
+/** @import { TransformationFunction } from '../src/index.js'; */
 
 import { createFileStream } from '../src/core.js';
 import { setGzipOSByteToUnknown } from '../test/utils.js';
 
+/** @type {TransformationFunction} */
 function timesTwo(row) {
   return [Number(row[0]) * 2, Number(row[1]) * 2];
 }
index 7764201311e1873f4883e3efcc33a78a02a247f9..707a1b7a2fd70dbc0b796bc2249da056c6bb7edd 100644 (file)
@@ -5,6 +5,7 @@
 // common CSV mangling by spreadsheet programs.
 
 import { CSVReader, CSVWriter, CSVNormalizer, CSVDenormalizer, CSVTransformer } from '../src/index.js';
+/** @import { TransformationFunction } from '../src/index.js'; */
 /** @import { CSVNormalizerHeader } from '../src/normalization.js'; */
 
 // A minimal declaration to tell `CSVNormalizer` to trim empty rows and columns but otherwise don't touch the data
@@ -18,6 +19,7 @@ const headers = [
   'sparse3'
 ];
 
+/** @type {TransformationFunction} */
 function transform(row) {
   let c = 0
   for (const field of row) {
This page took 0.0424 seconds and 4 git commands to generate.