csv-generator-client

Library to generate downloadable csv files from client side data.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
csv-generator-client
6202.1.14 years ago5 years agoMinified + gzip package size for csv-generator-client in KB

Readme

npm version CircleCI Coverage Status dependencies Codacy Badge Maintainability Greenkeeper badge Build Status Sauce Test Status
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