From 87b68b73a2b3f754f65d7bac393607fbff9b36d0 Mon Sep 17 00:00:00 2001 From: Jacob Morrison Date: Wed, 15 Jan 2025 22:59:06 -0600 Subject: [PATCH] Make newline a property in CsvValidationOptions --- src/csv.ts | 12 ++++++++---- src/types.ts | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/csv.ts b/src/csv.ts index 918d913..46da5ae 100644 --- a/src/csv.ts +++ b/src/csv.ts @@ -181,10 +181,8 @@ export async function validateCsv( } return new Promise((resolve, reject) => { - Papa.parse(input, { + const config = { header: false, - newline: "\n", - // chunkSize: 64 * 1024, beforeFirstChunk: (chunk) => { return removeBOM(chunk) }, @@ -197,6 +195,12 @@ export async function validateCsv( }, complete: () => handleParseEnd(resolve), error: (error: Error) => reject(error), - }) + }; + + if (options.newline) { + config.newline = options.newline; + } + + Papa.parse(input, config) }) } diff --git a/src/types.ts b/src/types.ts index 16a601e..45e6d5c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -44,6 +44,7 @@ export interface CsvValidatorVersion { export interface CsvValidationOptions { maxErrors?: number + newline?: string onValueCallback?: (value: { [key: string]: string }) => void }