Skip to content

Commit 486589d

Browse files
author
Danieth
committed
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 * #6
1 parent fa77e18 commit 486589d

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/core.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ export const jsonsHeaders = ((array) => Array.from(
1212
));
1313

1414
export const jsons2arrays = (jsons, headers) => {
15-
headers = headers || jsonsHeaders(jsons);
16-
return [headers, ...jsons.map((object) =>
17-
headers.map((header) =>
18-
object[header] ? object[header] : ''))]
15+
headers = headers || jsonsHeaders(jsons);
16+
const data = jsons.map((object) => headers.map((header) => (header in object) ? object[header] : ''));
17+
return [headers, ...data];
1918
};
2019

2120
export const joiner = ((data,separator = ',') =>

0 commit comments

Comments
 (0)