Browse Source

Added option `forceUniformNewline`

pull/845/head
Khoi Pham 4 years ago
parent
commit
89dca8a038
  1. 4
      papaparse.js
  2. 9
      tests/test-cases.js

4
papaparse.js

@ -1398,6 +1398,7 @@ License: MIT @@ -1398,6 +1398,7 @@ License: MIT
var step = config.step;
var preview = config.preview;
var fastMode = config.fastMode;
var forceUniformNewline = config.forceUniformNewline;
var quoteChar;
/** Allows for no quoteChar by setting quoteChar to undefined in config */
if (config.quoteChar === undefined) {
@ -1438,6 +1439,9 @@ License: MIT @@ -1438,6 +1439,9 @@ License: MIT
if (typeof input !== 'string')
throw new Error('Input must be a string');
if (forceUniformNewline)
input = input.replace(/(\r\n|\r|\n)/g, newline);
// We don't need to compute some of these every time parse() is called,
// but having them in a more local scope seems to perform better
var inputLen = input.length,

9
tests/test-cases.js

@ -585,6 +585,15 @@ var CORE_PARSER_TESTS = [ @@ -585,6 +585,15 @@ var CORE_PARSER_TESTS = [
data: [['a', 'b', 'c'], ['']],
errors: []
}
},
{
description: "Force uniform newline",
input: 'a,b,c\r\nd,e,f\ng,h,i\rj,k,l\n',
config: { forceUniformNewline: true },
expected: {
data: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ['j', 'k', 'l'], ['']],
errors: []
}
}
];

Loading…
Cancel
Save