2.0.1 • Published 3 years ago

arrays-to-csv v2.0.1

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

arrays-to-csv

NPM Module to write CSV files o string from Array

You can use this library in your projects to generate csv files from a simple javascript array of objects. This library give us the solution to export csv with diferents delimiters like ',' or ';' without problems.

Install

Using npm in Node.js project

npm install arrays-to-csv

Setup

Once the module is installed in your project, you must import it to be able to use it.

const arrayToCsv = require('arrays-to-csv');

data = [
    {
        field1: 'value1Row1',
        field2: 'value2Row1'
    },
    {
        field1: 'value1Row2',
        field2: 'value2Row2'
    }
]

var csvGenerator = new arrayToCsv(data, { delimiter: ',' });

get the csv String to manage the content in downloads, uploads...

To get the csv string, execute the method.

const arrayToCsv = require('arrays-to-csv');

data = [
    {
        field1: 'value1Row1',
        field2: 'value2Row1'
    },
    {
        field1: 'value1Row2',
        field2: 'value2Row2'
    }
]

//Create the generator
var csvGenerator = new arrayToCsv(data, { delimiter: ',' });

//Execute the method
var csv = csVGenerator.getCsv();

Download csv file to localhost

To download the csv file, indicate the path and execute the saveFile() method.

const arrayToCsv = require('arrays-to-csv');

data = [
    {
        field1: 'value1Row1',
        field2: 'value2Row1'
    },
    {
        field1: 'value1Row2',
        field2: 'value2Row2'
    }
]

//Create the generator
var csvGenerator = new arrayToCsv(data, { delimiter: ',' });

//Execute the method
csVGenerator.saveFile('./data.csv');

Params new arrayToCsv(data, params = {})

ParamDefault value
delimiter,
quote"
2.0.1

3 years ago

2.0.0

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago