Simple but reliable CSV parser/serializer.
- Simple and minimal.
- RFC 4180 compliant.
- Only few but necessary options.
- Can be easily wrapped to other API's.
- No deps.
import {CsvParser} from 'csv-ps';
const parser = new CsvParser();
const rows = parser.parseAll('1,2,3');
// rows: [['1', '2', '3']]
import {CsvParser} from 'csv-ps';
const parser = new CsvParser();
const rows = [];
parser.setCallback((row) => {
rows.push(row);
});
parser.parse('1');
parser.parse(',2,');
parser.parse('3\n');
parser.parse('4,5');
parser.parse(',6');
parser.end();
// rows: [['1', '2', '3'], ['4', '5', '6']]
import {CsvFileParser} from 'csv-ps';
const parser = CsvFileParser();
await parser.parse('/path/to/file.csv', (row) => {
console.log('Got a row: %O', row);
});
import {CsvSerializer} from 'csv-ps';
const serializer = new CsvSerializer();
const serialized = serializer.serializeAll([['a', 'b', 'c']]);
// serialized: '"a","b","c"\n'