Browse Source

fixcolumns config works with input type object (#919)

Closes #918
pull/912/head
Simon 3 years ago committed by GitHub
parent
commit
4132d810ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      papaparse.js
  2. 7
      tests/test-cases.js

2
papaparse.js

@ -307,7 +307,7 @@ License: MIT
if (Array.isArray(_input.data)) if (Array.isArray(_input.data))
{ {
if (!_input.fields) if (!_input.fields)
_input.fields = _input.meta && _input.meta.fields; _input.fields = _input.meta && _input.meta.fields || _columns;
if (!_input.fields) if (!_input.fields)
_input.fields = Array.isArray(_input.data[0]) _input.fields = Array.isArray(_input.data[0])

7
tests/test-cases.js

@ -1865,6 +1865,13 @@ var UNPARSE_TESTS = [
config: {columns: ['a', 'b', 'c']}, config: {columns: ['a', 'b', 'c']},
expected: 'a,b,c\r\n1,2,\r\n\r\n3,,4' expected: 'a,b,c\r\n1,2,\r\n\r\n3,,4'
}, },
{
description: "Column option used to manually specify keys with input type object",
notes: "Should not throw any error when attempting to serialize key not present in object. Columns are different than keys of the first object. When an object is missing a key then the serialized value should be an empty string.",
input: { data: [{a: 1, b: '2'}, {}, {a: 3, d: 'd', c: 4,}] },
config: {columns: ['a', 'b', 'c']},
expected: 'a,b,c\r\n1,2,\r\n\r\n3,,4'
},
{ {
description: "Use different escapeChar", description: "Use different escapeChar",
input: [{a: 'foo', b: '"quoted"'}], input: [{a: 'foo', b: '"quoted"'}],

Loading…
Cancel
Save