1.0.3 • Published 10 years ago

csv-model v1.0.3

Weekly downloads
4
License
ISC
Repository
github
Last release
10 years ago

csv-model

Convert your file or string csv to javascript object.

Installation

npm install csv-model

Usage

var CSVM = require('csv-model');
var str = 'name;value;\nNicolas;146\nRichard;665';

//By string
var obj = CSVM.fromString(str);
console.log(obj);
/*
obj = [{
            name: Nicolas,
            value:146
        },
        {
            name:Richard,
            value:665
        }]
*/

//By file
CSVM.fromFile('file.csv', null, function (err, obj) {
    console.log(obj);
    /*
    obj = [{
                name: Nicolas,
                value:146
            },
            {
                name:Richard,
                value:665
            }]
    */
});

Options

  • header: String
var CSVM = require('csv-model');
var str = 'Nicolas;146\nRichard;665\nJhony;965\nRonald;887';

//By string
var obj = CSVM.fromString(str, {header: 'name;value'});
/*
obj = [{
            name: Nicolas,
            value:146
        },
        {
            name:Richard,
            value:665
        },
        {
            name:Ronald,
            value:887
        }]
*/

//By file
var obj = CSVM.fromString('file.csv', {header: 'name;value'},
                function (err, obj) {
                  console.log(obj);
                  /*
                  obj = [{
                              name: Nicolas,
                              value:146
                          },
                          {
                              name:Richard,
                              value:665
                          }]
                  */
              });
1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago