csv-stringify
Advanced tools
Comparing version
# Changelog | ||
## Version 4.0.0 | ||
Backward incompatibilities: | ||
* formatters: rename bool to boolean | ||
New features: | ||
* formatters: handle number | ||
Cleanup | ||
* src: cache call to typeof | ||
* package: latest dependencies | ||
## Version 3.1.1 | ||
@@ -5,0 +20,0 @@ |
@@ -104,3 +104,3 @@ 'use strict'; | ||
var base, base1, base10, base11, base12, base13, base2, base3, base4, base5, base6, base7, base8, base9, k, options, v; | ||
var base, base1, base10, base11, base12, base13, base14, base2, base3, base4, base5, base6, base7, base8, base9, k, options, v; | ||
// Immutable options | ||
@@ -145,2 +145,7 @@ options = {}; | ||
} | ||
if (this.options.formatters.bool) { | ||
// Backward compatibility | ||
this.options.formatters.boolean = this.options.formatters.bool; | ||
} | ||
// Custom formatters | ||
if ((base10 = this.options.formatters).date == null) { | ||
@@ -152,4 +157,4 @@ base10.date = function (value) { | ||
} | ||
if ((base11 = this.options.formatters).bool == null) { | ||
base11.bool = function (value) { | ||
if ((base11 = this.options.formatters).boolean == null) { | ||
base11.boolean = function (value) { | ||
// Cast boolean to string by default | ||
@@ -163,4 +168,10 @@ if (value) { | ||
} | ||
if ((base12 = this.options.formatters).object == null) { | ||
base12.object = function (value) { | ||
if ((base12 = this.options.formatters).number == null) { | ||
base12.number = function (value) { | ||
// Cast number to string using native casting by default | ||
return '' + value; | ||
}; | ||
} | ||
if ((base13 = this.options.formatters).object == null) { | ||
base13.object = function (value) { | ||
// Stringify object as JSON by default | ||
@@ -170,4 +181,4 @@ return JSON.stringify(value); | ||
} | ||
if ((base13 = this.options).rowDelimiter == null) { | ||
base13.rowDelimiter = '\n'; | ||
if ((base14 = this.options).rowDelimiter == null) { | ||
base14.rowDelimiter = '\n'; | ||
} | ||
@@ -295,3 +306,3 @@ // Internal usage, state related | ||
Stringifier.prototype.stringify = function (line) { | ||
var _line, column, columns, containsEscape, containsQuote, containsRowDelimiter, containsdelimiter, delimiter, escape, field, i, j, l, newLine, quote, ref, ref1, regexp, shouldQuote, value; | ||
var _line, column, columns, containsEscape, containsQuote, containsRowDelimiter, containsdelimiter, delimiter, escape, field, i, j, l, newLine, quote, ref, ref1, regexp, shouldQuote, type, value; | ||
if ((typeof line === 'undefined' ? 'undefined' : _typeof(line)) !== 'object') { | ||
@@ -332,13 +343,14 @@ return line; | ||
field = line[i]; | ||
if (typeof field === 'string') { | ||
type = typeof field === 'undefined' ? 'undefined' : _typeof(field); | ||
if (type === 'string') { | ||
// fine 99% of the cases, keep going | ||
} else if (typeof field === 'number') { | ||
} else if (type === 'number') { | ||
// Cast number to string | ||
field = '' + field; | ||
} else if (typeof field === 'boolean') { | ||
field = this.options.formatters.bool(field); | ||
field = this.options.formatters.number(field); | ||
} else if (type === 'boolean') { | ||
field = this.options.formatters.boolean(field); | ||
} else if (field instanceof Date) { | ||
field = this.options.formatters.date(field); | ||
} else if ((typeof field === 'undefined' ? 'undefined' : _typeof(field)) === 'object' && field !== null) { | ||
} else if (type === 'object' && field !== null) { | ||
field = this.options.formatters.object(field); | ||
@@ -345,0 +357,0 @@ } |
@@ -98,3 +98,3 @@ // Generated by CoffeeScript 2.0.3 | ||
Stringifier = function(opts = {}) { | ||
var base, base1, base10, base11, base12, base13, base2, base3, base4, base5, base6, base7, base8, base9, k, options, v; | ||
var base, base1, base10, base11, base12, base13, base14, base2, base3, base4, base5, base6, base7, base8, base9, k, options, v; | ||
// Immutable options | ||
@@ -139,2 +139,7 @@ options = {}; | ||
} | ||
if (this.options.formatters.bool) { | ||
// Backward compatibility | ||
this.options.formatters.boolean = this.options.formatters.bool; | ||
} | ||
// Custom formatters | ||
if ((base10 = this.options.formatters).date == null) { | ||
@@ -146,4 +151,4 @@ base10.date = function(value) { | ||
} | ||
if ((base11 = this.options.formatters).bool == null) { | ||
base11.bool = function(value) { | ||
if ((base11 = this.options.formatters).boolean == null) { | ||
base11.boolean = function(value) { | ||
// Cast boolean to string by default | ||
@@ -157,4 +162,10 @@ if (value) { | ||
} | ||
if ((base12 = this.options.formatters).object == null) { | ||
base12.object = function(value) { | ||
if ((base12 = this.options.formatters).number == null) { | ||
base12.number = function(value) { | ||
// Cast number to string using native casting by default | ||
return '' + value; | ||
}; | ||
} | ||
if ((base13 = this.options.formatters).object == null) { | ||
base13.object = function(value) { | ||
// Stringify object as JSON by default | ||
@@ -164,4 +175,4 @@ return JSON.stringify(value); | ||
} | ||
if ((base13 = this.options).rowDelimiter == null) { | ||
base13.rowDelimiter = '\n'; | ||
if ((base14 = this.options).rowDelimiter == null) { | ||
base14.rowDelimiter = '\n'; | ||
} | ||
@@ -289,3 +300,3 @@ // Internal usage, state related | ||
Stringifier.prototype.stringify = function(line) { | ||
var _line, column, columns, containsEscape, containsQuote, containsRowDelimiter, containsdelimiter, delimiter, escape, field, i, j, l, newLine, quote, ref, ref1, regexp, shouldQuote, value; | ||
var _line, column, columns, containsEscape, containsQuote, containsRowDelimiter, containsdelimiter, delimiter, escape, field, i, j, l, newLine, quote, ref, ref1, regexp, shouldQuote, type, value; | ||
if (typeof line !== 'object') { | ||
@@ -325,13 +336,14 @@ return line; | ||
field = line[i]; | ||
if (typeof field === 'string') { | ||
type = typeof field; | ||
if (type === 'string') { | ||
// fine 99% of the cases, keep going | ||
} else if (typeof field === 'number') { | ||
} else if (type === 'number') { | ||
// Cast number to string | ||
field = '' + field; | ||
} else if (typeof field === 'boolean') { | ||
field = this.options.formatters.bool(field); | ||
field = this.options.formatters.number(field); | ||
} else if (type === 'boolean') { | ||
field = this.options.formatters.boolean(field); | ||
} else if (field instanceof Date) { | ||
field = this.options.formatters.date(field); | ||
} else if (typeof field === 'object' && field !== null) { | ||
} else if (type === 'object' && field !== null) { | ||
field = this.options.formatters.object(field); | ||
@@ -338,0 +350,0 @@ } |
{ | ||
"version": "3.1.1", | ||
"version": "4.0.0", | ||
"name": "csv-stringify", | ||
@@ -22,6 +22,6 @@ "description": "CSV stringifier implementing the Node.js `stream.Transform` API", | ||
"babel-preset-es2015": "^6.24.1", | ||
"coffeescript": "~2.0.1", | ||
"csv-generate": "~2.0.0", | ||
"mocha": "~4.0.1", | ||
"should": "~13.1.2" | ||
"coffeescript": "~2.3.1", | ||
"csv-generate": "~2.1.0", | ||
"mocha": "~5.2.0", | ||
"should": "~13.2.3" | ||
}, | ||
@@ -28,0 +28,0 @@ "optionalDependencies": {}, |
95016
1.07%896
2.75%