From 6183ce65f20068a7ff7a532115a6e3d84cdfe139 Mon Sep 17 00:00:00 2001 From: Lastofthefirst <47003973+Lastofthefirst@users.noreply.github.com> Date: Sat, 27 Mar 2021 13:22:03 -0400 Subject: [PATCH] Custom Script for tsv to json. boop. --- Scripts/tsvToJson.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Scripts/tsvToJson.js diff --git a/Scripts/tsvToJson.js b/Scripts/tsvToJson.js new file mode 100644 index 00000000..8a175b9b --- /dev/null +++ b/Scripts/tsvToJson.js @@ -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; +}