Merge pull request #7 from Danieth/master
Allowing falsy entries in json data. It fixes #6
This commit is contained in:
commit
d323141c98
2 changed files with 7 additions and 8 deletions
|
|
@ -12,10 +12,9 @@ export const jsonsHeaders = ((array) => Array.from(
|
||||||
));
|
));
|
||||||
|
|
||||||
export const jsons2arrays = (jsons, headers) => {
|
export const jsons2arrays = (jsons, headers) => {
|
||||||
headers = headers || jsonsHeaders(jsons);
|
headers = headers || jsonsHeaders(jsons);
|
||||||
return [headers, ...jsons.map((object) =>
|
const data = jsons.map((object) => headers.map((header) => (header in object) ? object[header] : ''));
|
||||||
headers.map((header) =>
|
return [headers, ...data];
|
||||||
object[header] ? object[header] : ''))]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const joiner = ((data,separator = ',') =>
|
export const joiner = ((data,separator = ',') =>
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ describe(`core::jsons2arrays`, () => {
|
||||||
sport: '97'
|
sport: '97'
|
||||||
}, {
|
}, {
|
||||||
maths: '77',
|
maths: '77',
|
||||||
sport: '99'
|
sport: 0
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
it(`converts an Array of literal objects to Array of arrays`, () => {
|
it(`converts an Array of literal objects to Array of arrays`, () => {
|
||||||
|
|
@ -109,7 +109,7 @@ describe(`core::jsons2arrays`, () => {
|
||||||
['maths', 'sport'],
|
['maths', 'sport'],
|
||||||
['90', ''],
|
['90', ''],
|
||||||
['', '97'],
|
['', '97'],
|
||||||
['77', '99']
|
['77', 0]
|
||||||
];
|
];
|
||||||
expect(actual).toEqual(expected);
|
expect(actual).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
@ -117,7 +117,7 @@ describe(`core::jsons2arrays`, () => {
|
||||||
it(`converts to Array of arrays following the order of headers`, () => {
|
it(`converts to Array of arrays following the order of headers`, () => {
|
||||||
const actual = jsons2arrays(fixtures, ['sport', 'maths']);
|
const actual = jsons2arrays(fixtures, ['sport', 'maths']);
|
||||||
const expected = [
|
const expected = [
|
||||||
['maths', 'sport'].reverse(), ['90', ''].reverse(), ['', '97'].reverse(), ['77', '99'].reverse()
|
['maths', 'sport'].reverse(), ['90', ''].reverse(), ['', '97'].reverse(), ['77', 0].reverse()
|
||||||
];
|
];
|
||||||
expect(actual).toEqual(expected);
|
expect(actual).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
@ -127,7 +127,7 @@ describe(`core::jsons2arrays`, () => {
|
||||||
const expected = [
|
const expected = [
|
||||||
headers, ['90', '', '', ''],
|
headers, ['90', '', '', ''],
|
||||||
['', '97', '', ''],
|
['', '97', '', ''],
|
||||||
['77', '99', '', '']
|
['77', 0, '', '']
|
||||||
];
|
];
|
||||||
expect(actual).toEqual(expected);
|
expect(actual).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue