Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

csv-stringify-as-promised

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csv-stringify-as-promised

csv-stringify wrapped in a promise

  • 3.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 31 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc