csv-readfile
v0.1.6
Published
Read CSV file as array of rows.
Downloads
5
Readme
csv-readfile
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' } ]