Modified jsonsHeaders#jsons2arrays to work with falsy keys
* `header in object` should be a sufficient condition. The suggested `String(object[header])` wasn't passing the original tests - it caused keys that didn't exist on the object to be inserted as undefined. Checking if the key is in the object allows for falsy values, while preventing keys that haven't ever been set from leaking in. * Should close issue #6 * https://github.com/abdennour/react-csv/issues/6
This commit is contained in:
parent
fa77e1852e
commit
486589d967
1 changed files with 3 additions and 4 deletions
|
|
@ -12,10 +12,9 @@ export const jsonsHeaders = ((array) => Array.from(
|
|||
));
|
||||
|
||||
export const jsons2arrays = (jsons, headers) => {
|
||||
headers = headers || jsonsHeaders(jsons);
|
||||
return [headers, ...jsons.map((object) =>
|
||||
headers.map((header) =>
|
||||
object[header] ? object[header] : ''))]
|
||||
headers = headers || jsonsHeaders(jsons);
|
||||
const data = jsons.map((object) => headers.map((header) => (header in object) ? object[header] : ''));
|
||||
return [headers, ...data];
|
||||
};
|
||||
|
||||
export const joiner = ((data,separator = ',') =>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue