1 | ## naivecsv
|
2 | ### A light and simple csv parser.
|
3 |
|
4 | <p align="center">
|
5 | <a href="https://npmcharts.com/compare/naivecsv?minimal=true"><img src="https://img.shields.io/npm/dm/naivecsv.svg" alt="Downloads"></a>
|
6 | <a href="https://www.npmjs.com/package/naivecsv"><img src="https://img.shields.io/npm/v/naivecsv.svg" alt="Version"></a>
|
7 | <a href="https://www.npmjs.com/package/naivecsv"><img src="https://img.shields.io/npm/l/naivecsv.svg" alt="License"></a>
|
8 | </p>
|
9 |
|
10 | ## Highlights
|
11 |
|
12 | - ES6 syntax, static method under class NaiveCsv
|
13 | - Customizable delimiter(default: ','), line-feed(default: '\r\n') and quote-mark(default: '\"')
|
14 | - Decoding configurable
|
15 | - Transpose available
|
16 | - Can delete blank trailing row
|
17 |
|
18 | ## Install
|
19 |
|
20 | ```console
|
21 | $ npm install naivecsv
|
22 | ```
|
23 |
|
24 | ## Usage
|
25 |
|
26 | ```js
|
27 | import { NaiveCsv } from 'naivecsv'
|
28 | import { promises as fsPromise } from 'fs'
|
29 |
|
30 | const file='[your csv file directory]'
|
31 |
|
32 | // simple usage
|
33 | fsPromise
|
34 | .readFile(file, 'utf-8')
|
35 | .then(text => {
|
36 | console.log(NaiveCsv.toRows(text, { popBlank: true }))
|
37 | })
|
38 |
|
39 | // more features
|
40 | fsPromise
|
41 | .readFile(file)
|
42 | .then(text => {
|
43 | console.log(
|
44 | NaiveCsv.toRows(text, {
|
45 | de: ',', // delimiter
|
46 | lf: '\r\n', // line-feed
|
47 | qt: '\"', // quotation mark
|
48 | transpose: false, // transpose the entire csv text as 2-d array
|
49 | decode: 'utf-8', // appoint decoding as 'utf-8'
|
50 | popBlank: true // delete blank trailing row
|
51 | }))
|
52 | })
|
53 | ```
|
54 |
|
55 | ## License
|
56 |
|
57 | [MIT](http://opensource.org/licenses/MIT)
|
58 |
|
59 | Copyright (c) 2019-present, Haoyang (Vincent) Wang
|