
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Simple and highly configurable CSV/TSV parser and encoder.
var csv = require('oh-csv');
var parser = new csv.Parser({
sep: ',',
linesep: ['\n', '\r', '\r\n'],
quote: '"',
esc: '\\'
});
parser.on('readable', function() {
var row;
while(row = parser.read()) {
console.log(row);
}
});
parser.write('1,Nicolas Froidure,nicolas.froidure@simplifield.com');
// [1, 'Nicolas Froidure', 'nicolas.froidure@simplifield.com']
parser.end();
Alternatively, you can specify fields to map them to an object properties:
var parser = new csv.Parser({
fields: ['id', 'name', 'email'], // fields are required for this mode
sep: ',',
linesep: ['\n', '\r', '\r\n'],
quote: '"',
esc: '\\'
});
parser.on('readable', function() {
var row;
while(row = parser.read()) {
console.log(row);
}
});
parser.write('1,Nicolas Froidure,nicolas.froidure@simplifield.com');
// {
// id: 1,
// name: 'Nicolas Froidure',
// email: 'nicolas.froidure@simplifield.com'
// }
parser.end();
var encoder = new csv.Encoder({
fields: ['id', 'name', 'email']
});
encoder.pipe(process.stdout);
// Array form
encoder.write([1, 'Nicolas Froidure', 'nicolas.froidure@simplifield.com']);
// '1,Nicolas Froidure,nicolas.froidure@simplifield.com'
// Object form (you need to specify fields)
encoder.write({
id:1,
email: 'nicolas.froidure@simplifield.com',
name: 'Nicolas Froidure'
});
// '1,Nicolas Froidure,nicolas.froidure@simplifield.com'
No library needed, DIY !
var fs = require('fs');
var parser = new csv.Parser();
var encoder = new csv.Encoder();
var Transform = require('stream').Transform;
var transformer = new Transform({objectMode: true});
transformer._transform = function(row, unused, cb) {
row[name] = row[name].toLowerCase();
this.push(row);
cb();
};
fs.createReadStream('mycsv.csv')
.pipe(parser)
.pipe(transformer)
.pipe(encoder)
.pipe(fs.createWriteStream('mycsv.new.csv'));
We've added a simple wrapper to get a CSV stream compatible with Excel for both OSX and Windows from a csv.encoder instance:
var encoder = new csv.Encoder(csv.tsvOpts);
csv.wrapForExcel(encoder)
.pipe(fs.createWriteStream('excel.csv'));
There are some CSV and TSV predefined objects in order to allow you to choose your format in a simpler manner.
CSV (Comma-Separated Values) as it's commonly found.
TSV (Tabulation-Separated Values)
The RFC 4180 CSV format.
Create a new CSV Parser transform stream with options
as defined in the
options section.
Create a new CSV Encoder transform stream with options
as defined in
the options section.
The options object is meant to be usable either with the Parser and the Encoder.
Default: [',']
The strings used for separating values. The first string is used to encode CSV. Separators can have several chars (useless thus essential).
Default: ['\r\n', '\r', '\n']
The strings used for separating lines. The first string is used to encode CSV.
Default: ['"']
The strings used for quoting values. The first string is used to encode CSV.
Default: An array containing options.sep
, options.linesep
strings.
If a field contains any occurrence of the given strings, it must be quoted.
Default: ['\\']
The strings used for escaping special chars. The first string is used to encode CSV.
Default: If options.esc
is empty, an empty array. If options.quote
is empty,
an array containing options.sep
, options.linesep
, options.quote
and
options.esc
strings, otherwise, an array containing options.quote
and
options.esc
.
The strings that must be escaped.
FAQs
Simple and parametrable CSV parser/encoder.
The npm package oh-csv receives a total of 125 weekly downloads. As such, oh-csv popularity was classified as not popular.
We found that oh-csv demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.