CSVParser.js
Usage
// Both arguments are optional. The csvData argument is a string// representing the contents of a .csv fileparser = csvData options ; parser; // get an array of arrays representing the dataparser; // get an array of objects, using the first row as keys parser data newCsvData // change data // change delimiter from comma to tab ; // change qualifier from double to single quotes parserdata; // get current CSV dataparser; // get the current delimiter (defaults to ',')parser; // get the current qualifier (defaults to '"') // You can pass in the following initialisation options, with example valuesparser = csvData delimiter: '\t' // defaults to ',' qualifier: "'" // defaults to '"', strict: false // defaults to true - throws error with rows of uneven length;
Compatibility
Works in browsers (optionally as an AMD module) or on the server. Browser support chart courtesy of testling-ci (take any red flags with a pinch of salt, it's been tested succcessfully in all these browsers - sometimes Testling times out!):
The tests use the legacy build, which include json2.js - use this if you need to support older browsers and are not already including json2.js.
License
Copyright (c) 2013 Rich Harris (@rich_harris). Released under an MIT license.