package
DSL for parsing CSV records
npm install csv-record-parserGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Create CSV record parsers in an abstract way
See also: csv-record-parser-stream
Install with npm
$ npm install csv-record-parserThe purpose of this library is to create abstract csv record parsers:
Abstract person parser
var parseNumber = require('parse-number');
module.exports = function person(csv){
return {
name: csv.col("name"),
age: parseNumber(csv.col("age")),
unknown: csv.ind(4)
}
}When reading csv:
var parser = require('csv-record-parser');
var person = require('person');
var csv = parser();
// input is some hypothetical csv library
input.on('header', function(header){
csv.header(header);
});
input.on('row', function(row){
csv.row(row);
people.emit(person(csv));
}) headers are .trim().toLowercase()d before lookups unless exact: true is
passed to options
options (Object)
exact (Boolean): header lookups match exactly (default: false)returns: a new RecordParser instance
Sets and gets the header, used for col lookups
header (Array): array of strings representing the headerSets and gets the row, used for col and ind lookups
row (Array): row dataname (String): name of columnreturns: row data in specified column
ind (Number): index into rowreturns: row[ind]
The MIT License (MIT)
Copyright (c) 2014 William Casarin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.