1.0.1 • Published 7 years ago

simple-csv-string v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Simple csv string

A simple js tool to render standards compliant csv's. See https://en.wikipedia.org/wiki/Comma-separated_values for the spec.

installation

npm install --save simple-csv-string

usage

var Csv = require('simple-csv-string');

// add the header line in the constructor
var csv = new Csv(['header1', 'header2', 'header3', 'header4', 'header5']);

// the length of subsequent added lines won't be modified if they are as long as the header
csv.addLine(['val11', 'val12', 'val13', 'val14', 'val15']);

// empty cells will be added if a line is shorter than the header
csv.addLine(['val21', 'val22', 'val23', 'val24']);

// cells will be removed if a line is longer than the header
csv.addLine([2, false, null, undefined, ' Super,\n"luxurious" truck  ', 'too much']);

console.log(csv.render());

// header1,header2,header3,header4,header5
// val11,val12,val13,val14,val15
// val21,val22,val23,val24,
// 2,false,,," Super,
// ""luxurious"" truck  "

build and test

npm install
npm test

or

node runTests