Browse Source

Allow multi-characters delimiter whe unparsing (#519)

pull/540/head
Adi Roiban 7 years ago committed by Sergi Almacellas Abellana
parent
commit
1e9daa0d4f
  1. 5
      papaparse.js
  2. 6
      tests/test-cases.js

5
papaparse.js

@ -271,7 +271,7 @@
/** whether to write headers */ /** whether to write headers */
var _writeHeader = true; var _writeHeader = true;
/** delimiting character */ /** delimiting character(s) */
var _delimiter = ','; var _delimiter = ',';
/** newline character(s) */ /** newline character(s) */
@ -326,8 +326,7 @@
return; return;
if (typeof _config.delimiter === 'string' if (typeof _config.delimiter === 'string'
&& _config.delimiter.length === 1 && !Papa.BAD_DELIMITERS.filter(function(value) { return _config.delimiter.indexOf(value) !== -1; }).length)
&& Papa.BAD_DELIMITERS.indexOf(_config.delimiter) === -1)
{ {
_delimiter = _config.delimiter; _delimiter = _config.delimiter;
} }

6
tests/test-cases.js

@ -1396,6 +1396,12 @@ var UNPARSE_TESTS = [
config: { delimiter: RECORD_SEP }, config: { delimiter: RECORD_SEP },
expected: 'a' + RECORD_SEP + 'b' + RECORD_SEP + 'c\r\nd' + RECORD_SEP + 'e' + RECORD_SEP + 'f' expected: 'a' + RECORD_SEP + 'b' + RECORD_SEP + 'c\r\nd' + RECORD_SEP + 'e' + RECORD_SEP + 'f'
}, },
{
description: "Custom delimiter (Multi-character)",
input: [['A', 'b', 'c'], ['d', 'e', 'f']],
config: { delimiter: ', ' },
expected: 'A, b, c\r\nd, e, f'
},
{ {
description: "Bad delimiter (\\n)", description: "Bad delimiter (\\n)",
notes: "Should default to comma", notes: "Should default to comma",

Loading…
Cancel
Save