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:
Danieth 2017-03-12 15:17:52 -04:00
commit 486589d967

View file

@ -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 = ',') =>