Skip to content

Commit

Permalink
Merge pull request #231 from sasjs/replace-csv-stringify
Browse files Browse the repository at this point in the history
fix: replace package csv-stringify with @fast-csv/format
  • Loading branch information
allanbowe authored Feb 21, 2023
2 parents b02a11f + 019e933 commit 6f818da
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 24 deletions.
100 changes: 89 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
"typescript": "4.5.4"
},
"dependencies": {
"@fast-csv/format": "4.3.5",
"@types/fs-extra": "9.0.13",
"@types/prompts": "2.0.13",
"chalk": "4.1.1",
"cli-table": "0.3.6",
"consola": "2.15.0",
"csv-stringify": "6.2.4",
"find": "0.3.0",
"fs-extra": "10.0.0",
"jwt-decode": "3.1.2",
Expand Down
18 changes: 6 additions & 12 deletions src/file/csvFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFile, createFile } from './file'
import { stringify, Input } from 'csv-stringify/sync'
import { writeToString, Row } from '@fast-csv/format'

/**
* reads a CSV file and returns parsed data
Expand All @@ -19,17 +19,14 @@ export const readCsv = async (csvFilePath: string): Promise<string[][]> => {
* creates a csv file at given path with provided data
* @param csvFilePath location where to create file
* @param csvData data which needs to be populated in file
* @param options a object which specify header and contains an array of column names
* @param headers an array of column names
*/
export const createCsv = async <T extends Input>(
export const createCsv = async <T extends Row[]>(
csvFilePath: string,
csvData: T,
options: {
header: boolean
columns: string[]
}
headers: string[]
) => {
const output = stringify(csvData, options)
const output = await writeToString(csvData, { headers })
await createFile(csvFilePath, output)
}

Expand Down Expand Up @@ -68,10 +65,7 @@ export const updateCsv = async (

csvData.push(newRecord)

await createCsv(csvFilePath, csvData, {
header: csvData.length === 1,
columns
})
await createCsv(csvFilePath, csvData, columns)
}

const validateInput = async (
Expand Down

0 comments on commit 6f818da

Please sign in to comment.