New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

json-csv

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-csv - npm Package Compare versions

Comparing version 0.0.8 to 0.1.0

57

json-csv.js

@@ -1,2 +0,36 @@

exports.toCSV = function(args, callback) {
var Readable = require("stream").Readable
var exporter = function() {
this.stream = null
}
exporter.prototype.prepValue = function(arg, forceQuoted) {
var quoted = forceQuoted || arg.indexOf('"') >= 0 || arg.indexOf(',') >= 0
var result = arg.replace(/\"/g,'""')
if (quoted)
result = '"' + result + '"'
return result
}
exporter.prototype.createReadStream = function(opts) {
this.stream = new Readable
this._toCSV(opts)
return this.stream
}
exporter.prototype.toCSV = function(args, callback) {
var s = this.createReadStream(args)
var result = ''
var buffer = null;
s.on('readable', function() {
buffer = s.read()
if (buffer !== null)
result += buffer
})
s.on('end', function() {
callback(null, result)
})
}
exporter.prototype._toCSV = function(args) {
var flatString = ''

@@ -14,2 +48,4 @@ var ix = 0

flatString += '\r\n'
this.stream.push(flatString)
flatString = ''
for(var jx = 0;jx<args.fields.length; jx++) {

@@ -31,13 +67,14 @@ if (jx > 0)

flatString += '\r\n'
callback(null, flatString)
this.stream.push(flatString)
this.stream.push(null)
}
exports.getValue = function(data, arg) {
exporter.prototype.getValue = function(data, arg) {
var args = arg.split('.')
if (args.length > 0)
return getValue(data, args, 0)
return this.getValueIx(data, args, 0)
return data[args[0]];
}
var getValue = function(data, args, ix) {
exporter.prototype.getValueIx = function(data, args, ix) {
var val = data[args[ix]]

@@ -48,3 +85,3 @@ if (typeof val === 'undefined')

if ((args.length-1) > ix)
return getValue(val, args, ix+1);
return this.getValueIx(val, args, ix+1);

@@ -54,8 +91,2 @@ return val;

exports.prepValue = function(arg, forceQuoted) {
var quoted = forceQuoted || arg.indexOf('"') >= 0 || arg.indexOf(',') >= 0
var result = arg.replace(/\"/g,'""')
if (quoted)
result = '"' + result + '"'
return result
}
module.exports = new exporter()
{
"name": "json-csv",
"version": "0.0.8",
"version": "0.1.0",
"description": "Export a richly structured, JSON array to CSV",
"homepage": "https://github.com/IWSLLC/json-csv",
"author": "Nathan Bridgewater <nathan@integratedwebsystems.com> (http://integratedwebsystems.com/)",
"author": "Nathan Bridgewater <nathan@iws.io> (http://iws.io/)",
"keywords": [

@@ -8,0 +8,0 @@ "csv",

Sorry, the diff of this file is not supported yet

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