csv-readfile

0.1.6 • Public • Published

csv-readfile

NPM

Read CSV file as array of rows.

const readFile = require('csv-readfile');
// readFile(<path>, [options])
// -> Promise [<row>]

// options: {
//   columns: true, // use columns: yes, first line
//   comment: '#', // single-line comment: #
//   escape: '"', // escape character: "
//   quote: '"',  // optional character surrounding field: "
//   trim: false,  // remove spaces around unquoted field: no
//   ltrim: false, // remove spaces left of unquoted field: no
//   rtrim: false, // remove spaces right of unquoted field: no
//   skip_empty_lines: false,
//   skip_lines_with_error: false,
//   skip_lines_with_empty_values: false,
//   delimiter: ',',     // end of field: ,
//   rowDelimiter: null, // end of row: \r, \n, or \r\n
//   from: NaN, // read from line: first
//   to: NaN    // read to line: last
// }


// FILE: indianobel.csv
// --------------------
# Indian & Indian-born Nobel laureates
year,field,name
1913,Literature,Rabindranath Tagore
1930,Physics,CV Raman
1968,Physiology or Medicine,Har Gobind Khorana
1979,Peace,Mother Teresa
1983,Physics,Subrahmanyan Chandrasekhar
1998,Economic Sciences,Amartya Sen
2009,Chemistry,Venkatraman Ramakrishnan
2014,Peace,Kailash Satyarthi

// CODE: read csv
// --------------
var data = await readFile('indianobel.csv');
// [ { year: '1913',
//     field: 'Literature',
//     name: 'Rabindranath Tagore' },
//   ...
//   { year: '2014', field: 'Peace', name: 'Kailash Satyarthi' } ]

Readme

Keywords

Package Sidebar

Install

npm i csv-readfile

Weekly Downloads

3

Version

0.1.6

License

MIT

Unpacked Size

2.8 kB

Total Files

4

Last publish

Collaborators

  • wolfram77