Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
formatted-stream
Advanced tools
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:
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);
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}
});
Type String
. Must be either xlsx, json, or csv.
Type Function
. A transformation function which is applied to each object before .on('data')
is triggered.
Default is function(data) { return data; }
.
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]}
.
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'
}
});
Type String
. Must be either xlsx, json, or csv.
Type Function
. A transformation function which is applied to each object before .on('data')
is triggered.
Default is function(data) { return data; }
.
Type Object
. An options object which will be passed to the CSV writer.
See fast-csv for more information.
Default is {}
.
Type Object
. An options object which will be passed to the JSON writer.
See JSONStream for more information.
Default is {}
.
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 {}
.
FAQs
Streaming XLSX, CSV, and JSON parser and writer
The npm package formatted-stream receives a total of 0 weekly downloads. As such, formatted-stream popularity was classified as not popular.
We found that formatted-stream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.