Browse Source

Merge pull request #346 from 12CU/header-option-for-unparse

Allow to unparse without headers
pull/325/merge
Sergi Almacellas Abellana 8 years ago committed by GitHub
parent
commit
6258a6aeae
  1. 8
      papaparse.js
  2. 6
      tests/test-cases.js

8
papaparse.js

@ -234,6 +234,9 @@
/** whether to surround every datum with quotes */ /** whether to surround every datum with quotes */
var _quotes = false; var _quotes = false;
/** whether to write headers */
var _writeHeader = true;
/** delimiting character */ /** delimiting character */
var _delimiter = ','; var _delimiter = ',';
@ -296,6 +299,9 @@
if (typeof _config.newline === 'string') if (typeof _config.newline === 'string')
_newline = _config.newline; _newline = _config.newline;
if (typeof _config.header === 'boolean')
_writeHeader = _config.header;
} }
@ -324,7 +330,7 @@
var dataKeyedByField = !(data[0] instanceof Array); var dataKeyedByField = !(data[0] instanceof Array);
// If there a header row, write it first // If there a header row, write it first
if (hasHeader) if (hasHeader && _writeHeader)
{ {
for (var i = 0; i < fields.length; i++) for (var i = 0; i < fields.length; i++)
{ {

6
tests/test-cases.js

@ -1152,6 +1152,12 @@ var UNPARSE_TESTS = [
description: "JSON null is treated as empty value", description: "JSON null is treated as empty value",
input: [{ "Col1": "a", "Col2": null, "Col3": "c" }], input: [{ "Col1": "a", "Col2": null, "Col3": "c" }],
expected: 'Col1,Col2,Col3\r\na,,c' expected: 'Col1,Col2,Col3\r\na,,c'
},
{
description: "Don't print header if header:false option specified",
input: [{ "Col1": "a", "Col2": "b", "Col3": "c" }, { "Col1": "d", "Col2": "e", "Col3": "f" }],
config: { header: false },
expected: 'a,b,c\r\nd,e,f'
} }
]; ];

Loading…
Cancel
Save