@haydenhigg/csv v1.0.2
@haydenhigg/csv
This is a package for easily creating and cleaning labelled data structures from CSV input files.
parse
csv.parse(`
A,B,C
1,2,3
1,4,9
1,16,81
`); /* =>
[
[ 'A', 'B', 'C' ],
[ '1', '2', '3' ],
[ '1', '4', '9' ],
[ '1', '16', '81' ],
]
*/
csv.parse(`
A,B,C
1,2,3
1,4,9
1,16,81
`, true); /* =>
[
{ A: '1', B: '2', C: '3' },
{ A: '1', B: '4', C: '9' },
{ A: '1', B: '16', C: '81' },
]
*/
The second argument specifies whether to use the first row of inputs as labels, default is false
.
readFile
Exactly the same as fs.readFile in NodeJS, except the callback function will use the parsed version of the text. As with parse, you can provide an optional extra argument to specify whether to use the first row of inputs as labels, but default is true
.
readFileSync
Exactly the same as fs.readFileSync in NodeJS, except it will return the parsed version of the text. As with parse, you can provide an optional extra argument to specify whether to use the first row of inputs as labels, but default is true
.
removeEmpty
Takes a parsed labelled CSV structure as input and returns one with any lines with missing data removed.