Comparing version 0.4.3 to 0.4.4
var extended = require("./extended"), | ||
has = extended.has, | ||
isUndefinedOrNull = extended.isUndefinedOrNull, | ||
@@ -18,3 +19,8 @@ trim = extended.trim, | ||
NEXT_TOKEN_REGEXP = new RegExp("([^\\s]|\\r\\n|\\n|\\r|" + delimiter + ")"), | ||
LINE_BREAK = /(\r\n|\n|\r)/; | ||
ROW_DELIMITER = /(\r\n|\n|\r)/, | ||
COMMENT, hasComments; | ||
if (has(options, "comment")) { | ||
COMMENT = options.comment; | ||
hasComments = true; | ||
} | ||
@@ -75,3 +81,3 @@ function formatItem(item) { | ||
throw new Error("Parse Error: expected: '" + ESCAPE + "' got: '" + nextToken + "'. at '" + str.substr(cursor, 10).replace(/[\r\n]/g, "\\n" + "'")); | ||
} else if (hasMoreData && (!nextToken || !LINE_BREAK.test(nextToken))) { | ||
} else if (hasMoreData && (!nextToken || !ROW_DELIMITER.test(nextToken))) { | ||
cursor = null; | ||
@@ -85,2 +91,16 @@ } | ||
function parseCommentLine(line, cursor, hasMoreData) { | ||
var nextIndex = line.substr(cursor).search(ROW_DELIMITER); | ||
if (nextIndex === -1) { | ||
if (hasMoreData) { | ||
nextIndex = null; | ||
} else { | ||
nextIndex = line.length + 1; | ||
} | ||
} else { | ||
nextIndex = (cursor + nextIndex) + 1; //go past the next line break | ||
} | ||
return nextIndex; | ||
} | ||
function parseItem(line, items, cursor, hasMoreData) { | ||
@@ -104,3 +124,3 @@ var searchStr = line.substr(cursor), | ||
} | ||
} else if (LINE_BREAK.test(nextChar)) { | ||
} else if (ROW_DELIMITER.test(nextChar)) { | ||
items.push(formatItem(searchStr.substr(0, nextIndex))); | ||
@@ -135,3 +155,3 @@ cursor += nextIndex; | ||
break; | ||
} else if (LINE_BREAK.test(token)) { | ||
} else if (ROW_DELIMITER.test(token)) { | ||
i = nextToken.cursor + 1; | ||
@@ -145,2 +165,14 @@ if (i < l) { | ||
} | ||
} else if (hasComments && token === COMMENT) { | ||
cursor = parseCommentLine(line, i, hasMoreData); | ||
if (cursor === null) { | ||
i = lastLineI; | ||
break; | ||
} else if (cursor < l) { | ||
lastLineI = i = cursor; | ||
} else { | ||
i = cursor; | ||
cursor = null; | ||
break; | ||
} | ||
} else { | ||
@@ -147,0 +179,0 @@ if (token === ESCAPE) { |
{ | ||
"name": "fast-csv", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"description": "CSV parser and writer", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -31,2 +31,3 @@ [![build status](https://secure.travis-ci.org/C2FO/fast-csv.png)](http://travis-ci.org/C2FO/fast-csv) | ||
* `ltrim=false`: If you want to left trim all values parsed set to true. | ||
* `comment=null`: If your CSV contains comments you can use this option to ignore lines that begin with the specified character (e.g. `#`). | ||
@@ -33,0 +34,0 @@ |
Sorry, the diff of this file is not supported yet
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
107006
679
526