A simple utility to manipulate and transform csv strings of data.
npm install csv-utilitiesA simple utility to manipulate and transform csv strings of data.
``bash`
npm i csv-utilities
`javascript
const csv = require('csv-util')
csv.csv2array(csv)
// returns a mutlidimensional array
`
`javascript
const csv = require('csv-util')
csv.array2csv(array)
// returns a csv string
`
Switches the order of two columns in the csv string
switchColumnsOrder(csvString, column1, column2)
`javascript
csv.switchColumnsOrder(csv, 1, 4)
// outputs a csv string with the columns 1 and 4 switched
`
Sorts each column in a row lowest to highest or alphabetically
`javascript`
csv.sortColumns(csv)
Reverses the order of all the rows
`javascript`
csv.reverseRows(csv)
Averages the numbers in each column in a row and creates an array
`csv`
1, 2, 3
2, 1, 3
outputs:
`javascript`
[2 , 2]
Appends an array of columns into the csv
appending this:
`javascript`
[5, 6]
to this:
`csv`
1, 2, 4
2, 1, 3
outputs:
`csv``
1, 2, 3, 5
2, 1, 3, 6