csv-stringify
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -1,6 +0,2 @@ | ||
// Generated by CoffeeScript 2.0.1 | ||
// # CSV Stringifier | ||
// Please look at the [README], the [samples] and the [tests] for additional | ||
// information. | ||
// Generated by CoffeeScript 1.12.7 | ||
var Stringifier, get, stream, util; | ||
@@ -14,11 +10,2 @@ | ||
// ## Usage | ||
// Callback approach, for ease of use: | ||
// `stringify(data, [options], callback)` | ||
// Stream API, for maximum of power: | ||
// `stringify([options], [callback])` | ||
module.exports = function() { | ||
@@ -84,8 +71,7 @@ var callback, chunks, data, options, stringifier; | ||
// ## `Stringifier([options])` | ||
// Options are documented [here](http://csv.adaltas.com/stringify/). | ||
Stringifier = function(opts = {}) { | ||
Stringifier = function(opts) { | ||
var base, base1, base10, base11, base12, base13, base2, base3, base4, base5, base6, base7, base8, base9, k, options, v; | ||
// Immutable options | ||
if (opts == null) { | ||
opts = {}; | ||
} | ||
options = {}; | ||
@@ -97,3 +83,2 @@ for (k in opts) { | ||
stream.Transform.call(this, options); | ||
//# Default options | ||
this.options = options; | ||
@@ -132,3 +117,2 @@ if ((base = this.options).delimiter == null) { | ||
base10.date = function(value) { | ||
// Cast date to timestamp string by default | ||
return '' + value.getTime(); | ||
@@ -139,3 +123,2 @@ }; | ||
base11.bool = function(value) { | ||
// Cast boolean to string by default | ||
if (value) { | ||
@@ -150,3 +133,2 @@ return '1'; | ||
base12.object = function(value) { | ||
// Stringify object as JSON by default | ||
return JSON.stringify(value); | ||
@@ -158,3 +140,2 @@ }; | ||
} | ||
// Internal usage, state related | ||
if (this.countWriten == null) { | ||
@@ -186,5 +167,2 @@ this.countWriten = 0; | ||
// ## `Stringifier.prototype.headers` | ||
// Print the header line if the option "header" is "true". | ||
Stringifier.prototype.headers = function() { | ||
@@ -199,3 +177,2 @@ var k, label, labels; | ||
labels = this.options.columns; | ||
// If columns is an object, keys are fields and values are labels | ||
if (typeof labels === 'object') { | ||
@@ -233,3 +210,2 @@ labels = (function() { | ||
preserve = typeof chunk !== 'object'; | ||
// Emit and stringify the record | ||
if (!preserve) { | ||
@@ -247,3 +223,2 @@ if (this.countWriten === 0 && !Array.isArray(chunk)) { | ||
} | ||
// Convert the record into a string | ||
if (this.options.eof) { | ||
@@ -259,4 +234,3 @@ chunk = this.stringify(chunk) + this.options.rowDelimiter; | ||
if (typeof chunk === 'number') { | ||
// Emit the csv | ||
chunk = `${chunk}`; | ||
chunk = "" + chunk; | ||
} | ||
@@ -272,3 +246,2 @@ if (this.countWriten === 0) { | ||
// ## `Stringifier.prototype._transform(line)` | ||
Stringifier.prototype._transform = function(chunk, encoding, callback) { | ||
@@ -279,5 +252,2 @@ 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) { | ||
@@ -310,5 +280,3 @@ var _line, column, columns, containsEscape, containsLinebreak, containsQuote, containsdelimiter, delimiter, escape, field, i, j, l, newLine, quote, ref, ref1, regexp, shouldQuote, value; | ||
_line = null; | ||
} 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 | ||
} else if (columns) { | ||
line.splice(columns.length); | ||
@@ -322,5 +290,3 @@ } | ||
// fine 99% of the cases, keep going | ||
} else if (typeof field === 'number') { | ||
// Cast number to string | ||
field = '' + field; | ||
@@ -363,5 +329,1 @@ } 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,15 +0,13 @@ | ||
// Generated by CoffeeScript 2.0.1 | ||
// # CSV Stringify Sync | ||
// Provides a synchronous alternative to the CSV stringifier. | ||
// Usage: `data = stringify(records, [options]` | ||
// Generated by CoffeeScript 1.12.7 | ||
var StringDecoder, stringify; | ||
({StringDecoder} = require('string_decoder')); | ||
StringDecoder = require('string_decoder').StringDecoder; | ||
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 = []; | ||
@@ -16,0 +14,0 @@ if (records instanceof Buffer) { |
{ | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"name": "csv-stringify", | ||
@@ -4,0 +4,0 @@ "description": "CSV stringifier implementing the Node.js `stream.Transform` API", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15635
369