csv-parse
Advanced tools
Comparing version 2.1.0 to 2.2.0
# Changelog | ||
## Version 2.2.0 | ||
* cast: deprecate auto_parse | ||
* auto_parse: function get context as second argument | ||
## Version 2.1.0 | ||
@@ -5,0 +10,0 @@ |
@@ -170,10 +170,16 @@ 'use strict'; | ||
} | ||
if ((base10 = this.options).auto_parse == null) { | ||
base10.auto_parse = false; | ||
if (this.options.auto_parse != null) { | ||
this.options.cast = this.options.auto_parse; | ||
} | ||
if ((base11 = this.options).auto_parse_date == null) { | ||
base11.auto_parse_date = false; | ||
if ((base10 = this.options).cast == null) { | ||
base10.cast = false; | ||
} | ||
if (this.options.auto_parse_date === true) { | ||
this.options.auto_parse_date = function (value) { | ||
if (this.options.auto_parse_date != null) { | ||
this.options.cast_date = this.options.auto_parse_date; | ||
} | ||
if ((base11 = this.options).cast_date == null) { | ||
base11.cast_date = false; | ||
} | ||
if (this.options.cast_date === true) { | ||
this.options.cast_date = function (value) { | ||
var m; | ||
@@ -394,3 +400,3 @@ m = Date.parse(value); | ||
var areNextCharsDelimiter, areNextCharsRowDelimiters, auto_parse, char, err, escapeIsQuote, i, isDelimiter, isEscape, isNextCharAComment, isQuote, isRowDelimiter, isRowDelimiterLength, is_float, is_int, l, ltrim, nextCharPos, ref, ref1, ref2, ref3, ref4, ref5, remainingBuffer, rowDelimiter, rtrim, wasCommenting; | ||
var areNextCharsDelimiter, areNextCharsRowDelimiters, cast, char, err, escapeIsQuote, i, isDelimiter, isEscape, isNextCharAComment, isQuote, isRowDelimiter, isRowDelimiterLength, is_float, is_int, l, ltrim, nextCharPos, ref, ref1, ref2, ref3, ref4, ref5, remainingBuffer, rowDelimiter, rtrim, wasCommenting; | ||
is_int = function is_int(value) { | ||
@@ -410,10 +416,23 @@ if (typeof _this2.is_int === 'function') { | ||
}; | ||
auto_parse = function auto_parse(value) { | ||
if (!_this2.options.auto_parse) { | ||
cast = function cast(value) { | ||
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (!_this2.options.cast) { | ||
return value; | ||
} | ||
if (typeof _this2.options.auto_parse === 'function') { | ||
return _this2.options.auto_parse(value); | ||
if (context.quoting == null) { | ||
context.quoting = !!_this2._.closingQuote; | ||
} | ||
// auto_parse == true | ||
if (context.count == null) { | ||
context.count = _this2.count; | ||
} | ||
if (context.index == null) { | ||
context.index = _this2._.line.length; | ||
} | ||
if (context.column == null) { | ||
context.column = Array.isArray(_this2.options.columns) ? _this2.options.columns[context.index] : context.index; | ||
} | ||
if (typeof _this2.options.cast === 'function') { | ||
return _this2.options.cast(value, context); | ||
} | ||
if (is_int(value)) { | ||
@@ -423,4 +442,4 @@ value = parseInt(value); | ||
value = parseFloat(value); | ||
} else if (_this2.options.auto_parse_date) { | ||
value = _this2.options.auto_parse_date(value); | ||
} else if (_this2.options.cast_date) { | ||
value = _this2.options.cast_date(value, context); | ||
} | ||
@@ -532,7 +551,7 @@ return value; | ||
} else { | ||
i++; | ||
this._.quoting = false; | ||
this._.closingQuote = this.options.quote.length; | ||
i++; | ||
if (end && i === l) { | ||
this._.line.push(auto_parse(this._.field || '')); | ||
this._.line.push(cast(this._.field || '')); | ||
this._.field = null; | ||
@@ -587,3 +606,3 @@ } | ||
} | ||
this._.line.push(auto_parse(this._.field || '')); | ||
this._.line.push(cast(this._.field || '')); | ||
this._.closingQuote = 0; | ||
@@ -650,3 +669,3 @@ this._.field = null; | ||
} | ||
this._.line.push(auto_parse(this._.field || '')); | ||
this._.line.push(cast(this._.field || '')); | ||
this._.field = null; | ||
@@ -653,0 +672,0 @@ } |
@@ -160,10 +160,16 @@ // Generated by CoffeeScript 2.2.3 | ||
} | ||
if ((base10 = this.options).auto_parse == null) { | ||
base10.auto_parse = false; | ||
if (this.options.auto_parse != null) { | ||
this.options.cast = this.options.auto_parse; | ||
} | ||
if ((base11 = this.options).auto_parse_date == null) { | ||
base11.auto_parse_date = false; | ||
if ((base10 = this.options).cast == null) { | ||
base10.cast = false; | ||
} | ||
if (this.options.auto_parse_date === true) { | ||
this.options.auto_parse_date = function(value) { | ||
if (this.options.auto_parse_date != null) { | ||
this.options.cast_date = this.options.auto_parse_date; | ||
} | ||
if ((base11 = this.options).cast_date == null) { | ||
base11.cast_date = false; | ||
} | ||
if (this.options.cast_date === true) { | ||
this.options.cast_date = function(value) { | ||
var m; | ||
@@ -373,3 +379,3 @@ m = Date.parse(value); | ||
Parser.prototype.__write = function(chars, end) { | ||
var areNextCharsDelimiter, areNextCharsRowDelimiters, auto_parse, char, err, escapeIsQuote, i, isDelimiter, isEscape, isNextCharAComment, isQuote, isRowDelimiter, isRowDelimiterLength, is_float, is_int, l, ltrim, nextCharPos, ref, ref1, ref2, ref3, ref4, ref5, remainingBuffer, rowDelimiter, rtrim, wasCommenting; | ||
var areNextCharsDelimiter, areNextCharsRowDelimiters, cast, char, err, escapeIsQuote, i, isDelimiter, isEscape, isNextCharAComment, isQuote, isRowDelimiter, isRowDelimiterLength, is_float, is_int, l, ltrim, nextCharPos, ref, ref1, ref2, ref3, ref4, ref5, remainingBuffer, rowDelimiter, rtrim, wasCommenting; | ||
is_int = (value) => { | ||
@@ -389,10 +395,21 @@ if (typeof this.is_int === 'function') { | ||
}; | ||
auto_parse = (value) => { | ||
if (!this.options.auto_parse) { | ||
cast = (value, context = {}) => { | ||
if (!this.options.cast) { | ||
return value; | ||
} | ||
if (typeof this.options.auto_parse === 'function') { | ||
return this.options.auto_parse(value); | ||
if (context.quoting == null) { | ||
context.quoting = !!this._.closingQuote; | ||
} | ||
// auto_parse == true | ||
if (context.count == null) { | ||
context.count = this.count; | ||
} | ||
if (context.index == null) { | ||
context.index = this._.line.length; | ||
} | ||
if (context.column == null) { | ||
context.column = Array.isArray(this.options.columns) ? this.options.columns[context.index] : context.index; | ||
} | ||
if (typeof this.options.cast === 'function') { | ||
return this.options.cast(value, context); | ||
} | ||
if (is_int(value)) { | ||
@@ -402,4 +419,4 @@ value = parseInt(value); | ||
value = parseFloat(value); | ||
} else if (this.options.auto_parse_date) { | ||
value = this.options.auto_parse_date(value); | ||
} else if (this.options.cast_date) { | ||
value = this.options.cast_date(value, context); | ||
} | ||
@@ -511,7 +528,7 @@ return value; | ||
} else { | ||
i++; | ||
this._.quoting = false; | ||
this._.closingQuote = this.options.quote.length; | ||
i++; | ||
if (end && i === l) { | ||
this._.line.push(auto_parse(this._.field || '')); | ||
this._.line.push(cast(this._.field || '')); | ||
this._.field = null; | ||
@@ -566,3 +583,3 @@ } | ||
} | ||
this._.line.push(auto_parse(this._.field || '')); | ||
this._.line.push(cast(this._.field || '')); | ||
this._.closingQuote = 0; | ||
@@ -627,3 +644,3 @@ this._.field = null; | ||
} | ||
this._.line.push(auto_parse(this._.field || '')); | ||
this._.line.push(cast(this._.field || '')); | ||
this._.field = null; | ||
@@ -630,0 +647,0 @@ } |
{ | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"name": "csv-parse", | ||
@@ -4,0 +4,0 @@ "description": "CSV parsing 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
67639
1638