Skip to content

Commit

Permalink
fix: bump csv-stringify
Browse files Browse the repository at this point in the history
  • Loading branch information
sabhas committed Feb 21, 2023
1 parent 86fb21d commit 4805b98
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ module.exports = {
statements: -10
}
},
collectCoverageFrom: ['src/**/{!(index),}.ts']
collectCoverageFrom: ['src/**/{!(index),}.ts'],
moduleNameMapper: {
'^csv-stringify/sync':
'<rootDir>/node_modules/csv-stringify/dist/cjs/sync.cjs'
}
}
14 changes: 7 additions & 7 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 @@ -56,7 +56,7 @@
"chalk": "4.1.1",
"cli-table": "0.3.6",
"consola": "2.15.0",
"csv-stringify": "5.6.5",
"csv-stringify": "6.2.4",
"find": "0.3.0",
"fs-extra": "10.0.0",
"jwt-decode": "3.1.2",
Expand Down
24 changes: 13 additions & 11 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 from 'csv-stringify/lib/sync'
import { stringify, Input } from 'csv-stringify/sync'

/**
* reads a CSV file and returns parsed data
Expand All @@ -19,18 +19,17 @@ 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 columns an array of header for file, i.e column names
* @param options a object which specify header and contains an array of column names
*/
export const createCsv = async (
export const createCsv = async <T extends Input>(
csvFilePath: string,
csvData: any[][],
columns: string[]
csvData: T,
options: {
header: boolean
columns: string[]
}
) => {
const output = stringify(csvData, {
header: csvData.length === 1,
columns: columns
})

const output = stringify(csvData, options)
await createFile(csvFilePath, output)
}

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

csvData.push(newRecord)

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

const validateInput = async (
Expand Down
3 changes: 1 addition & 2 deletions src/file/spec/csvFile.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'path'
import fs from 'fs-extra'
import { updateCsv, readCsv, createCsv } from '../csvFile'
import { updateCsv } from '../csvFile'
import * as fileModule from '../file'

const csvFilePath = path.join(__dirname, 'tests-csv')
Expand Down

0 comments on commit 4805b98

Please sign in to comment.