CSV-ES
CSV-ES is a universal JavaScript CSV parser designed specifically to be simple, fast, and spec compliant.
Features
- RFC Compliant
- ECMAScript Module
- CommonJS Compatible
- Typescript Compatible
Installation
npm install csv-es
;
or
;
CSV.parse()
Takes a string of CSV data and converts it to a 2 dimensional array of [entries][values]
Arguments
CSV.parse(csv, {options}, reviver(value, row, col)) : [entries][values]
- csv - the CSV string to parse
- options
- typed - infer types (default
false
)
- typed - infer types (default
- reviver1 - a custom function to modify the output (default
(value) => value
)
1 Values for row
and col
are 1-based.
Example
;const csv = `"header1,header2,header3""aaa,bbb,ccc""zzz,yyy,xxx"`;const parsed = CSVconsole;> > "header1" "header2" "header3" > "aaa" "bbb" "ccc" > "zzz" "yyy" "xxx" >
CSV.stringify()
Takes a 2 dimensional array of [entries][values]
and converts them to CSV
Arguments
CSV.stringify(array, {options}, replacer(value, row, col)) : string
- array - the input array to stringify
- options
- eof - add a trailing newline at the end of file (default
true
)
- eof - add a trailing newline at the end of file (default
- replacer1 - a custom function to modify the values (default
(value) => value
)
1 Values for row
and col
are 1-based.
Example
;const data = "header1" "header2" "header3" "aaa" "bbb" "ccc" "zzz" "yyy" "xxx" ;const stringified = CSVconsole;> "header1,header2,header3"> "aaa,bbb,ccc"> "zzz,yyy,xxx"
CommonJS
A .cjs
bundle is included for CommonJS compatibility
CSV.parse()
const CSV = ;const csv = // the csv stringconst data = CSV;
CSV.stringify()
const CSV = ;const data = // the a 2-dimensional arrayconst csv = CSV;
Typescript
Typings are generated from JSDoc using Typescript. They are 100% compatible with VSCode Intellisense and will work seamlessly with Typescript.