Socket
Socket
Sign inDemoInstall

csv-stringify

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csv-stringify - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

CHANGELOG.md

101

lib/index.js

@@ -1,2 +0,6 @@

// Generated by CoffeeScript 1.10.0
// Generated by CoffeeScript 2.0.1
// # CSV Stringifier
// Please look at the [README], the [samples] and the [tests] for additional
// information.
var Stringifier, get, stream, util;

@@ -10,2 +14,11 @@

// ## Usage
// Callback approach, for ease of use:
// `stringify(data, [options], callback)`
// Stream API, for maximum of power:
// `stringify([options], [callback])`
module.exports = function() {

@@ -71,7 +84,8 @@ var callback, chunks, data, options, stringifier;

Stringifier = function(opts) {
var base, base1, base10, base11, base12, base2, base3, base4, base5, base6, base7, base8, base9, k, options, v;
if (opts == null) {
opts = {};
}
// ## `Stringifier([options])`
// Options are documented [here](http://csv.adaltas.com/stringify/).
Stringifier = function(opts = {}) {
var base, base1, base10, base11, base12, base13, base2, base3, base4, base5, base6, base7, base8, base9, k, options, v;
// Immutable options
options = {};

@@ -83,2 +97,3 @@ for (k in opts) {

stream.Transform.call(this, options);
//# Default options
this.options = options;

@@ -94,27 +109,32 @@ if ((base = this.options).delimiter == null) {

}
if ((base3 = this.options).quotedString == null) {
base3.quotedString = false;
if ((base3 = this.options).quotedEmpty == null) {
base3.quotedEmpty = void 0;
}
if ((base4 = this.options).eof == null) {
base4.eof = true;
if ((base4 = this.options).quotedString == null) {
base4.quotedString = false;
}
if ((base5 = this.options).escape == null) {
base5.escape = '"';
if ((base5 = this.options).eof == null) {
base5.eof = true;
}
if ((base6 = this.options).columns == null) {
base6.columns = null;
if ((base6 = this.options).escape == null) {
base6.escape = '"';
}
if ((base7 = this.options).header == null) {
base7.header = false;
if ((base7 = this.options).columns == null) {
base7.columns = null;
}
if ((base8 = this.options).formatters == null) {
base8.formatters = {};
if ((base8 = this.options).header == null) {
base8.header = false;
}
if ((base9 = this.options.formatters).date == null) {
base9.date = function(value) {
if ((base9 = this.options).formatters == null) {
base9.formatters = {};
}
if ((base10 = this.options.formatters).date == null) {
base10.date = function(value) {
// Cast date to timestamp string by default
return '' + value.getTime();
};
}
if ((base10 = this.options.formatters).bool == null) {
base10.bool = function(value) {
if ((base11 = this.options.formatters).bool == null) {
base11.bool = function(value) {
// Cast boolean to string by default
if (value) {

@@ -127,10 +147,12 @@ return '1';

}
if ((base11 = this.options.formatters).object == null) {
base11.object = function(value) {
if ((base12 = this.options.formatters).object == null) {
base12.object = function(value) {
// Stringify object as JSON by default
return JSON.stringify(value);
};
}
if ((base12 = this.options).rowDelimiter == null) {
base12.rowDelimiter = '\n';
if ((base13 = this.options).rowDelimiter == null) {
base13.rowDelimiter = '\n';
}
// Internal usage, state related
if (this.countWriten == null) {

@@ -162,2 +184,5 @@ this.countWriten = 0;

// ## `Stringifier.prototype.headers`
// Print the header line if the option "header" is "true".
Stringifier.prototype.headers = function() {

@@ -172,2 +197,3 @@ var k, label, labels;

labels = this.options.columns;
// If columns is an object, keys are fields and values are labels
if (typeof labels === 'object') {

@@ -200,3 +226,3 @@ labels = (function() {

Stringifier.prototype.write = function(chunk, encoding, callback) {
var base, e, error, preserve;
var base, e, preserve;
if (chunk == null) {

@@ -206,2 +232,3 @@ return;

preserve = typeof chunk !== 'object';
// Emit and stringify the record
if (!preserve) {

@@ -219,2 +246,3 @@ if (this.countWriten === 0 && !Array.isArray(chunk)) {

}
// Convert the record into a string
if (this.options.eof) {

@@ -230,3 +258,4 @@ chunk = this.stringify(chunk) + this.options.rowDelimiter;

if (typeof chunk === 'number') {
chunk = "" + chunk;
// Emit the csv
chunk = `${chunk}`;
}

@@ -242,2 +271,3 @@ if (this.countWriten === 0) {

// ## `Stringifier.prototype._transform(line)`
Stringifier.prototype._transform = function(chunk, encoding, callback) {

@@ -248,2 +278,5 @@ this.push(chunk);

// ## `Stringifier.prototype.stringify(line)`
// Convert a line to a string. Line may be an object, an array or a string.
Stringifier.prototype.stringify = function(line) {

@@ -267,3 +300,3 @@ var _line, column, columns, containsEscape, containsLinebreak, containsQuote, containsdelimiter, delimiter, escape, field, i, j, l, newLine, quote, ref, ref1, regexp, shouldQuote, value;

value = get(line, column);
_line[i] = typeof value === 'undefined' || value === null ? '' : value;
_line[i] = (typeof value === 'undefined' || value === null) ? '' : value;
}

@@ -277,3 +310,5 @@ } else {

_line = null;
} else if (columns) {
} else if (columns) { // Note, we used to have @options.columns
// We are getting an array but the user want specified output columns. In
// this case, we respect the columns indexes
line.splice(columns.length);

@@ -287,3 +322,5 @@ }

// fine 99% of the cases, keep going
} else if (typeof field === 'number') {
// Cast number to string
field = '' + field;

@@ -326,1 +363,5 @@ } else if (typeof field === 'boolean') {

};
// [readme]: https://github.com/wdavidw/node-csv-stringify
// [samples]: https://github.com/wdavidw/node-csv-stringify/tree/master/samples
// [tests]: https://github.com/wdavidw/node-csv-stringify/tree/master/test

@@ -1,13 +0,15 @@

// Generated by CoffeeScript 1.10.0
// Generated by CoffeeScript 2.0.1
// # CSV Stringify Sync
// Provides a synchronous alternative to the CSV stringifier.
// Usage: `data = stringify(records, [options]`
var StringDecoder, stringify;
StringDecoder = require('string_decoder').StringDecoder;
({StringDecoder} = require('string_decoder'));
stringify = require('./index');
module.exports = function(records, options) {
module.exports = function(records, options = {}) {
var data, decoder, i, len, record, stringifier;
if (options == null) {
options = {};
}
data = [];

@@ -14,0 +16,0 @@ if (records instanceof Buffer) {

{
"version": "1.0.4",
"version": "1.1.0",
"name": "csv-stringify",

@@ -9,13 +9,13 @@ "description": "CSV stringifier implementing the Node.js `stream.Transform` API",

"type": "git",
"url": "http://www.github.com/wdavidw/node-csv-stringify"
"url": "http://www.github.com/adaltas/node-csv-stringify"
},
"homepage": "http://csv.adaltas.com/stringify/",
"dependencies": {
"lodash.get": "^4.0.0"
"lodash.get": "~4.4.2"
},
"devDependencies": {
"coffee-script": "latest",
"csv-generate": "latest",
"mocha": "latest",
"should": "latest"
"coffeescript": "~2.0.1",
"csv-generate": "~1.0.0",
"mocha": "~4.0.1",
"should": "~13.1.2"
},

@@ -27,4 +27,4 @@ "optionalDependencies": {},

"pretest": "./node_modules/.bin/coffee -b -o lib src",
"test": "NODE_ENV=test ./node_modules/.bin/mocha --compilers coffee:coffee-script/register --reporter dot"
"test": "NODE_ENV=test ./node_modules/.bin/mocha test/**/*.coffee"
}
}

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

[![Build Status](https://secure.travis-ci.org/wdavidw/node-csv-stringify.png)](http://travis-ci.org/wdavidw/node-csv-stringify)
[![Build Status](https://secure.travis-ci.org/adaltas/node-csv-stringify.svg)][travis]

@@ -62,3 +62,3 @@ Part of the [CSV module][csv_home], this project is a stringifier converting

[examples]: http://csv.adaltas.com/stringify/examples/
[csv]: https://github.com/wdavidw/node-csv
[travis]: https://travis-ci.org/#!/wdavidw/node-csv-stringify
[csv]: https://github.com/adaltas/node-csv
[travis]: https://travis-ci.org/#!/adaltas/node-csv-stringify
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