Add JSONtoCSV

Resolve #686
This commit is contained in:
Angelos Chalaris
2018-07-06 20:25:46 +03:00
parent 67601cff1b
commit 7443e9270f
5 changed files with 52 additions and 2 deletions

View File

@ -0,0 +1,11 @@
const JSONtoCSV = (arr, columns, delimiter = ',') =>
[
columns.join(delimiter),
...arr.map(obj =>
columns.reduce(
(acc, key) => `${acc}${!acc.length ? '' : delimiter}"${!obj[key] ? '' : obj[key]}"`,
''
)
)
].join('\n');
module.exports = JSONtoCSV;