Skip to content

Instantly share code, notes, and snippets.

@alexkrolick
Last active November 18, 2020 08:10
Show Gist options
  • Save alexkrolick/aa00171d085d94683c74bf89f4198b0d to your computer and use it in GitHub Desktop.
Save alexkrolick/aa00171d085d94683c74bf89f4198b0d to your computer and use it in GitHub Desktop.
// this is a very naive parser that only works on simple tables
// - no nesting
// - no cells that contain \t (tab) characters
// Usage:
// tsv`
// "Name" \t "Price"
// "Apple" \t 2.50
// `
function tsv(strings, ...expressions) {
const rows = strings.join("").split("\n");
// const data = rows.map(row => row.split("\t").map(v => JSON.parse(v.trim())));
const data = rows.map(row => row.split("\t").map(v => v.trim()));
return data;
}
export default tsv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment