CSV-JS - A Comma-Separated Values parser for JS
Built to rfc4180 standard, with options for adjusting strictness:
- optional carriage returns for non-microsoft sources
- automatically type-cast numeric an boolean values
- relaxed mode which: ignores blank lines, ignores garbage following quoted tokens, does not enforce a consistent record length
Adopted for UnityBase by pavel.mash
var csv = require('@unitybase/base').csv;
// simple
var rows = csv.parse('one,two,three\nfour,five,six', ',')
// rows equals [["one","two","three"],["four","five","six"]]
// or read from file system
var fs = require('fs'), f = fs.readFileSync('c:/csv.txt');
var rows = csv.parse(f);
for( var i =0; i < rows.length; i++){
console.log(rows[i]);
}
Methods
# parse (str: String, commaopt: String) → Array inner
rfc4180 standard csv parse with options for strictness and data type conversion. By default, will automatically type-cast numeric an boolean values.
Return:
An array records, each of which is an array of scalar values.