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

formatted-stream

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formatted-stream

Streaming XLSX, CSV, and JSON parser and writer

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

formatted-stream Build Status

A universal wrapper around file format parsers.
Currently supports in- and output in CSV, JSON, and XLSX format.

## Usage

Install formatted-stream:

npm install formatted-stream --save

Include and use in your code:

ES5
const fs = require('fs'),
  formattedStream = require('formatted-stream').default,
  parser = formattedStream.from('json'),
  writer = formattedStream.to('csv');

parser.pipe(writer);
writer.pipe(fs.createWriteStream('out.csv'));
fs.createReadStream('in.json').pipe(parser);
ES6
import fs from 'fs';
import formattedStream from 'formatted-stream';

const parser = formattedStream.from('json'),
  writer = formattedStream.to('csv');

parser.pipe(writer);
writer.pipe(fs.createWriteStream('out.csv'));
fs.createReadStream('in.json').pipe(parser);

## API Documentation

### .from(format, options)

const parser = formattedStream.from('csv', {
  transform: function(data) { return data; },
  csv: {headers: false}
});
format

Type String. Must be either xlsx, json, or csv.

options.transform

Type Function. A transformation function which is applied to each object before .on('data') is triggered.
Default is function(data) { return data; }.

options.csv

Type Object. An options object which will be passed to the CSV parser.
See fast-csv for more information.
Default is {headers: true}.

#### options.json

Type Object. The value of options.json.path will be passed to JSONStream.parse.
See JSONStream for more information.
Default is {path: [true]}.

options.xlsx

Type Object. An options object which will be passed to the XLSX parser. Set the XLSX worksheet by defining options.xlsx.sheet. Default: Sheet 1
See ExcelJS for more options.
Default is {sheet: 'Sheet 1'}.

### .to(format, options)

const writer = formattedStream.to('json', {
  transform: function(data) { return data; },
  csv: {headers: false},
  json: {
    open: '[\n',
    sep: '\n,\n',
    close: '\n]\n'
  }
});
format

Type String. Must be either xlsx, json, or csv.

options.transform

Type Function. A transformation function which is applied to each object before .on('data') is triggered.
Default is function(data) { return data; }.

options.csv

Type Object. An options object which will be passed to the CSV writer.
See fast-csv for more information.
Default is {}.

options.json

Type Object. An options object which will be passed to the JSON writer.
See JSONStream for more information.
Default is {}.

options.xlsx

Type Object. An options object which will be passed to the XLSX writer. Assign a function to options.xlsx.headerAccessor in order to transform all header fields according to the output of the function. Set the XLSX worksheet by defining options.xlsx.sheet. If no sheet is defined, the XLSX parser will write all sheets in the document to the CSV file. Default: undefined.
See ExcelJS for more options.
Default is {}.

Keywords

FAQs

Package last updated on 09 Aug 2016

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