Skip to content

Commit

Permalink
Custom Script for tsv to json.
Browse files Browse the repository at this point in the history
boop.
  • Loading branch information
Lastofthefirst authored Mar 27, 2021
1 parent 775e1b9 commit 6183ce6
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Scripts/tsvToJson.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
{
"api":1,
"name":"TSV to JSON",
"description":"Converts TSV to JSON",
"author":"Quddus George",
"icon":"table",
"tags":"tab, tsv, json, table"
}
**/

//credit for tsv function: https://gist.github.com/iwek/7154706#gistcomment-3369283

function main(state) {
function tsvJSON(tsv) {
return tsv
.split("\n")
.map((line) => line.split("\t"))
.reduce((a, c, i, d) => {
if (i) {
const item = Object.fromEntries(c.map((val, j) => [d[0][j], val]));
return a ? [...a, item] : [item];
}
}, []);
}
let json = JSON.stringify(tsvJSON(state.fullText));
state.fullText = json;
}

0 comments on commit 6183ce6

Please sign in to comment.