simple-csv-string

1.0.1 • Public • Published

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

/simple-csv-string/

    Package Sidebar

    Install

    npm i simple-csv-string

    Weekly Downloads

    17

    Version

    1.0.1

    License

    MIT

    Last publish

    Collaborators

    • bvellacott