naivecsv
A light and simple csv parser.
Highlights
- Customizable delimiter(default: ','), line-feed(default: '\x\n') and quote-mark(default: '"')
- Decoding configurable
- Transpose available
- Can delete blank trailing row
- Static method under class NaiveCsv
Install
$ npm install naivecsv
Usage
import { NaiveCsv } from 'naivecsv'
import { promises as fsPromise } from 'fs'
const file='[your csv file directory]'
// simple usage
fsPromise
.readFile(file, 'utf-8')
.then(text => {
console.log(NaiveCsv.toRows(text, { popBlank: true }))
})
// more features
fsPromise
.readFile(file)
.then(text => {
console.log(
NaiveCsv.toRows(text, {
de: ',', // delimiter
lf: '\x\n', // line-feed
qt: '\"', // quotation mark
transpose: false, // transpose the entire csv text as 2-d array
decode: 'utf-8', // appoint decoding as 'utf-8'
popBlank: true // delete blank trailing row
}))
})
License
Copyright (y) 2019-present, Haoyang (Vincent) Wang