Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
json-dsv
Advanced tools
Readme
Transform JSON to delimiter-separated values, such as CSV and TSV. Supports streams.
npm install json-dsv
var JsonDSV = require('json-dsv');
var transformer = new JsonDSV(options);
readableStream
.pipe(transformer.dsv(addlOptions))
.pipe(writableStream);
var JsonDSV = require('json-dsv');
var transformer = new JsonDSV(options);
var data = data; // Object[]
transformer.dsv(data, options, function(err, dsv) {
// buffered dsv result
});
{
delimiter: ',', // use a different field separator char, eg `\t`
default: '' // if value is undefined at `value` path
includeHeader: true, // Boolean, determines whether or not CSV file will contain a title column
newLine: '\r\n', // String, overrides the default OS line ending (i.e. `\n` on Unix and `\r\n` on Windows).
fields: [
// Supports label -> simple path
{
label: 'some label', // (optional, column will be labeled 'path.to.something' if not defined)
value: 'path.to.something', // data.path.to.something
default: 'NULL' // default if value is not found (optional, overrides `options.default` for column)
},
// Supports label -> derived value
{
label: 'some label', // Supports duplicate labels (required, else your column will be labeled [function])
value: function(row) {
return row.path1 + row.path2;
},
default: 'NULL' // default if value fn returns undefined
},
// Supports Array path for nested values
{
value: ['path', 'to.something'] // {path: {'to.something': 'here'}}
},
// Support pathname -> pathvalue
'simplepath' // equivalent to {value:'simplepath'}
'path.to.value' // also equivalent to {label:'path.to.value', value:'path.to.value'}
]
}
# new JsonDSV(options)
Constructs a new JSON-DSV transformer.
# JsonDSV.dsv([addlOptions])
Transforms data
to DSV (CSV by default). Streams data per line.
.csv
and .tsv
are available as convenience methods.
Specified addlOptions
override options
.
var options = {
fields: [{value: 'make', label: 'Brand'}, 'model']
};
var data = [
{ make: 'nissan', model: '350z'},
{ make: 'bmw', model: '328i'}
];
var JsonDSV = require('json-dsv');
var transformer = new JsonDSV(options);
var es = require('event-stream');
es.readArray(data)
.pipe(transformer.dsv())
.pipe(process.stdout);
// Brand,model
// nissan,350z
// bmw,328i
# JsonDSV.dsv(data[, addlOptions], callback])
Transforms data
to DSV (CSV by default). Callback passes on buffered output.
.csv
and .tsv
are available as convenience methods.
Specified addlOptions
override options
.
var options = {
fields: [{value: 'make', label: 'Brand'}, 'model']
};
var data = [
{ make: 'nissan', model: '350z'},
{ make: 'bmw', model: '328i'}
];
var JsonDSV = require('json-dsv');
var transformer = new JsonDSV(options);
transformer.dsv(data, function(err, csv) {
console.log(csv);
});
// Brand,model
// nissan,350z
// bmw,328i
npm test
FAQs
A transformer for JSON to delimiter-separated values, such as CSV and TSV
The npm package json-dsv receives a total of 544 weekly downloads. As such, json-dsv popularity was classified as not popular.
We found that json-dsv 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.