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

csv-write-stream

Package Overview
Dependencies
Maintainers
3
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csv-write-stream

A CSV encoder stream that produces properly escaped CSVs

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22K
decreased by-57.17%
Maintainers
3
Weekly downloads
 
Created
Source

csv-write-stream

A CSV encoder stream that produces properly escaped CSVs.

NPM

browser support

A through stream. Write arrays of strings (or JS objects) and you will receive a properly escaped CSV stream out the other end.

usage

var writer = csvWriter([options])
var csvWriter = require('csv-write-stream')
var writer = csvWriter()

writer is a duplex stream -- you can pipe data to it and it will emit a string for each line of the CSV

default options
{
  separator: ',',
  newline: '\n',
  headers: undefined,
  sendHeaders: true
}

headers can be an array of strings to use as the header row. if you don't specify a header row the keys of the first row written to the stream will be used as the header row IF the first row is an object (see the test suite for more details). if the sendHeaders option is set to false, the headers will be used for ordering the data but will never be written to the stream.

example of auto headers:

var writer = csv()
writer.pipe(fs.createWriteStream('out.csv'))
writer.write({hello: "world", foo: "bar", baz: "taco"})
writer.end()

// produces: hello,foo,baz\nworld,bar,taco\n

example of specifying headers:

var writer = csv({ headers: ["hello", "foo"]})
writer.pipe(fs.createWriteStream('out.csv'))
writer.write(['world', 'bar'])
writer.end()

// produces: hello,foo\nworld,bar\n

example of not sending headers:

var writer = csv({sendHeaders: false})
writer.pipe(fs.createWriteStream('out.csv'))
writer.write({hello: "world", foo: "bar", baz: "taco"})
writer.end()

// produces: world,bar,taco\n

see the test suite for more examples

run the test suite

$ npm install
$ npm test

cli usage

This module also includes a CLI, which you can pipe ndjson to stdin and it will print csv on stdout. You can install it with npm install -g csv-write-stream.

cat example.ndjson | csv-write-stream > example.csv

FAQs

Package last updated on 17 Mar 2015

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