csv-to-ndjson

1.0.1 • Public • Published

csv-to-ndjson Build Status

Convert a CSV file to ndjson format stream or file.

Install

$ npm install csv-to-ndjson

Usage

const csvToNdjson = require('csv-to-ndjson');
 
csvToNdjson('financialdata.csv', {
    delimiter: ';'
    header: ['Q1', 'Q2', 'Q3', 'Q4']
}).pipe(// Some pipe operation);
// => Returns a readable stream of ndjson
 
csvToNdjson('financialdata.csv', {
    delimiter: ';',
    destination: 'financialdata.json',
    header: ['Q1', 'Q2', 'Q3', 'Q4']
}).then(succes => // do something on success)
// => Returns a promise when the file is written

API

csvToNdjson(input, [options])

path

Type: string

Path of the CSV file to be read. The file has to end with the .csv file extension.

options

destination

Type: string

When destination exists on the options object, the results of the transformation are persisted in a file. When a destination is specified the function doesn't return a readable stream but a promise when the file is written.

delimiter

Type: char
Default: ,

If the CSV uses ; delimiter instead of , then this needs to be declared explicitly in the options object.

header

Type: String[]

When you want to use custom attribute names and not the headers of the CSV file as attribute names, then you can specify an array of attribute names.

License

MIT © Simon

Package Sidebar

Install

npm i csv-to-ndjson

Weekly Downloads

2

Version

1.0.1

License

MIT

Last publish

Collaborators

  • simonja