Browse Source

Merge 7c73643e25 into 23e1b47f5c

pull/836/merge
alexander-gush 4 years ago committed by GitHub
parent
commit
5b5d50c069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      docs/docs.html
  2. 10
      papaparse.js
  3. 7
      tests/test-cases.js

11
docs/docs.html

@ -260,7 +260,8 @@ @@ -260,7 +260,8 @@
header: true,
newline: "\r\n",
skipEmptyLines: false, //other option is 'greedy', meaning skip delimiters, quotes, and whitespace.
columns: null //or array of strings
columns: null, //or array of strings
quoteDataWithSpaces: true
}
</code></pre>
</div>
@ -338,6 +339,14 @@ @@ -338,6 +339,14 @@
If <code>data</code> is an array of objects this option can be used to manually specify the keys (columns) you expect in the objects. If not set the keys of the first objects are used as column.
</td>
</tr>
<tr>
<td>
<code>quoteDataWithSpaces</code>
</td>
<td>
If <code>false</code>, field values that have spaces in the start or in the end will not be enclosed in quotes.
</td>
</tr>
<tr>
<td>
<code>escapeFormulae</code>

10
papaparse.js

@ -285,6 +285,9 @@ License: MIT @@ -285,6 +285,9 @@ License: MIT
/** whether to prevent outputting cells that can be parsed as formulae by spreadsheet software (Excel and LibreOffice) */
var _escapeFormulae = false;
/** whether to surround every datum that has spaces in the start or in the end with quotes */
var _quoteDataWithSpaces = true;
unpackConfig();
var quoteCharRegex = new RegExp(escapeRegExp(_quoteChar), 'g');
@ -369,6 +372,9 @@ License: MIT @@ -369,6 +372,9 @@ License: MIT
if (typeof _config.escapeFormulae === 'boolean')
_escapeFormulae = _config.escapeFormulae;
if (typeof _config.quoteDataWithSpaces === 'boolean')
_quoteDataWithSpaces = _config.quoteDataWithSpaces;
}
@ -455,8 +461,8 @@ License: MIT @@ -455,8 +461,8 @@ License: MIT
|| (Array.isArray(_quotes) && _quotes[col])
|| hasAny(escapedQuoteStr, Papa.BAD_DELIMITERS)
|| escapedQuoteStr.indexOf(_delimiter) > -1
|| escapedQuoteStr.charAt(0) === ' '
|| escapedQuoteStr.charAt(escapedQuoteStr.length - 1) === ' ';
|| (_quoteDataWithSpaces && escapedQuoteStr.charAt(0) === ' ')
|| (_quoteDataWithSpaces && escapedQuoteStr.charAt(escapedQuoteStr.length - 1) === ' ');
return needsQuotes ? _quoteChar + escapedQuoteStr + _quoteChar : escapedQuoteStr;
}

7
tests/test-cases.js

@ -1906,6 +1906,13 @@ var UNPARSE_TESTS = [ @@ -1906,6 +1906,13 @@ var UNPARSE_TESTS = [
config: { escapeFormulae: true, quotes: true, quoteChar: "'", escapeChar: "'" },
expected: '\'Col1\',\'Col2\',\'Col3\'\r\n\'\'\'=danger\',\'\'\'@danger\',\'safe\'\r\n\'safe=safe\',\'\'\'+danger\',\'\'\'-danger, danger\'\r\n\'\'\'+safe\',\'\'\'@safe\',\'safe, safe\''
},
{
description: "Use quoteDataWithSpaces set to false",
notes: "Papa should not add quotes to data with spaces in the start or in the end)",
input: { data: ["abc", "d", " ef "] },
config: { quoteDataWithSpaces: false },
expected: 'abc,d, ef '
},
];
describe('Unparse Tests', function() {

Loading…
Cancel
Save