diff options
Diffstat (limited to 'client/data.js')
| -rw-r--r-- | client/data.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/client/data.js b/client/data.js new file mode 100644 index 0000000..855da4a --- /dev/null +++ b/client/data.js @@ -0,0 +1,37 @@ +const files = [ + // "gun_violence", + "mass_shootings_from_columbine", + "firearms_manufactured", + "ar_15_2016_18", +] +const parse = require('csv-parse') + +const dataPromises = files.map(name => { + return fetch('./data/' + name + '.csv').then(rows => { + return rows.text() + }).then(text => { + return new Promise((resolve, reject) => { + parse(text, {}, (_, lines) => resolve(lines)) + }) + }).then(lines => { + // console.log(name, lines) + const h = lines.shift() + return { + name, + h, + lines: lines.filter(s => !!s) + } + }) +}) +const allPromises = Promise.all(dataPromises).then(data => { + return data.reduce((a,b) => { + // console.log(b) + a[b.name] = b + return a + }, {}) +}) +const load = () => { + return allPromises +} + +export { load } |
