Skip to content

Latest commit

 

History

History
48 lines (37 loc) · 1.69 KB

README.md

File metadata and controls

48 lines (37 loc) · 1.69 KB

json-csv-transformer

transform json to csv, and vice versa

node npm license Build Status Standard - JavaScript Style Guide Coveralls Status

Install

npm install json-csv-transformer --save

Use

import CSV from 'json-csv-transformer'

const csv = new CSV({
  schema: [{
    key: 'xxx',
    label: 'XXX',
    type: 'string',
  }]
})

// parse data, csv or json
csv.parse(data)
// get file dataURL
csv.getDataURL()
// transform to JSON
csv.toJSON()

find more use case, please see test

Schema

field type required description
key string true key for this schema
label string false it will display in the header
type string | boolean | date | number false default type is string, it will be ignored if formatter is present
formatter {csv: function, json: function} false custom formatter, csv for transform to csv, json for transform to json