Skip to content

Instantly share code, notes, and snippets.

View izaacdb's full-sized avatar

Izaac Broadbent izaacdb

View GitHub Profile
@izaacdb
izaacdb / csvtojson.ts
Last active May 16, 2018 09:49
CSV to JSON in ES6
export const csvToJson = (csv: string) => {
const brands = csv.split('\n') || 'error';
const titles = brands.shift().split(','); //takes first row
const json = brands
.map((b: any) => {
const brand = b.split(',');
return brand
.map(
// Reducer
export const examples = (state: any = [], {type, payload}) => {
switch (type) {
case 'ADD_EXAMPLES':
console.log(state);
return payload;
case 'CREATE_EXAMPLES':
return [...state, payload];
case 'UPDATE_EXAMPLES':
return state.map(example => {