Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

csv-stringify-as-promised

2.0.3 • Public • Published

MIT License Build Status

NPM status

csv-stringify-as-promised

The csv-stringify is great, but it doesn't support promises! This module is a lightweight promise wrapper around it. The only prod dependency is csv-stringify.

Usage

const stringify = require('csv-stringify-as-promised');
const assert = require('assert');
 
const input = [ [ '1', '2', '3', '4' ], [ 'a', 'b', 'c', 'd' ] ];
 
stringify(input).then((output) => {
  assert.equal(output,
`1,2,3,4
a,b,c,d
`);
}).catch((err) => {
  assert.fail(err);
});

You can pass any csv-stringify options by passing an object as the second argument.

const stringify = require('csv-stringify-as-promised');
const assert = require('assert');
const options = { quotedString: true }
const input = [ [ '1', '2', '3', '4' ], [ 'a', 'b', 'c', 'd' ] ];
 
stringify(input, options).then((output) => {
  assert.equal(output,
`"1","2","3","4"
"a","b","c","d"
`);
}).catch((err) => {
  assert.fail(err);
});

Use your own promise library

By default, this module uses Node's builtin Promise object, but if you prefer to use a different promise library, you can do so simply by overwriting the Promise property on the module.

const stringify = require('csv-stringify-as-promised');
const bluebird = require('bluebird');
 
stringify.Promise = bluebird;
 
const input = [ [ '1', '2', '3', '4' ], [ 'a', 'b', 'c', 'd' ] ];
 
stringify(input).then((output) => {
  // uses bluebird instead of Promise
}).catch((err) => {
  // handle error
});

Use your own csv-stringify library

By default, this module uses csv-stringify library, but if you prefer to use a different CSV library, you can do so simply by overwriting the csvStringify property on the module.

const stringify = require('csv-stringify-as-promised');
 
stringify.csvStringify = yourCustomLibrary;

Requirements

This module requires NodeJS 8 or greater

Tests

npm t

Keywords

install

npm i csv-stringify-as-promised

Downloadsweekly downloads

844

version

2.0.3

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability