csv-generator-client
v2.1.1
Published
Library to generate downloadable csv files from client side data.
Downloads
703
Readme
csv-generator-client
Library to generate downloadable csv files from client side data.
Installing
npm install csv-generator-client
This package requires lodash/fp
, so make sure that's available in your app.
Usage
import * as generator from 'csv-generator-client'
let settings = {separator: '|', addQuotes: true}
generator.download({settings, fileName, dataArray})
Or
var generator = require('csv-generator-client')
// In this case the default settings are used.
generator.download({fileName: fileName, dataArray: dataArray})
API
getLinkElement
getLinkElement({settings: settings, fileName: fileName, dataArray: dataArray})
Where settings can be:
{
separator: String,
addQuotes: Boolean,
autoDetectColumns: Boolean, // Requires an array of objects (e.g., [{name: 'Bob'}, {name: 'Joe'}])
columnKeys: [String] // Each element is a key in the row object (e.g., 'name')
}
Default settings are:
{
separator: ',',
addQuotes: false,
autoDetectColumns: false,
}
fileName
is required
dataArray
is required to be an array of objects if autoDetectColumns
is true
, otherwise an array of arrays.
download
download({settings: settings, fileName: fileName, dataArray: dataArray})
Where settings can be:
{
separator: String,
addQuotes: Boolean,
autoDetectColumns: Boolean, // Requires an array of objects (e.g., [{name: 'Bob'}, {name: 'Joe'}])
columnKeys: [String] // Each element is a key in the row object (e.g., 'name')
}
Default settings are:
{
separator: ',',
addQuotes: false,
autoDetectColumns: false,
}
fileName
is required
dataArray
is required to be an array of objects if autoDetectColumns
is true
, otherwise an array of arrays.
Credits
This implementation is based on csv-repository-client by AlexLibs