Skip to content

Instantly share code, notes, and snippets.

@sanusart
Last active March 31, 2019 06:24
Show Gist options
  • Save sanusart/2a4237a9c43a6335186dda93b465effc to your computer and use it in GitHub Desktop.
Save sanusart/2a4237a9c43a6335186dda93b465effc to your computer and use it in GitHub Desktop.
TSV to object #tsv #csv #lodash
export const tsvToObject = () =>
fetch('https://www.file.com/some.tsv')
.then(r => r.text())
.then(tsv => {
const data = compact(tsv.split('\n'));
const headers = head(data).split('\t');
const rows = map(row => row.split('\t'), tail(data));
return keyBy('SOME_HEADER', rows.map(m => zipObject(headers, m)));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment