Skip to content

Commit

Permalink
Merge pull request #250 from Lastofthefirst/patch-1
Browse files Browse the repository at this point in the history
Custom Script for tsv to json.
  • Loading branch information
IvanMathy authored Jul 27, 2022
2 parents 2c30ad5 + 6183ce6 commit f0dc0c2
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 f0dc0c2

Please sign in to comment.