const csvToJson = (arr: any[]) => {
const keys = Object.keys(arr[0])
return arr.reduce(
(p, c) => `${p}\n${keys.map((k) => c[k]).join(',')}`,
keys.join(','),
)
}
const jsonToCsv = (str: string) => {
const rows = str.split('\n')
const keys = rows[0].split(',')
return rows.slice(1).reduce<any>(
(p, c) => [
...p,
c.split(',').reduce(
(pp, cc, i) => ({
...pp,
[keys[i]]: cc,
}),
{},
),
],
[],
)
}