diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-03-30 16:09:32 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-03-30 16:09:32 +0530 |
commit | aaf950e2ad5c07d4423f9822e3a0ae9f7b8d2bdf (patch) | |
tree | 9274139660f30c4857d80044eb4ac283aac1775a /src/webex/pages/show-db.ts | |
parent | 15e18440dbad55df19977a2eb7053681259afc18 (diff) | |
download | wallet-core-aaf950e2ad5c07d4423f9822e3a0ae9f7b8d2bdf.tar.xz |
re-format with prettier v2, fix HTML
Diffstat (limited to 'src/webex/pages/show-db.ts')
-rw-r--r-- | src/webex/pages/show-db.ts | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/src/webex/pages/show-db.ts b/src/webex/pages/show-db.ts index d95951385..16ea80d2d 100644 --- a/src/webex/pages/show-db.ts +++ b/src/webex/pages/show-db.ts @@ -14,15 +14,19 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ - /** * Wallet database dump for debugging. * * @author Florian Dold */ -function replacer(match: string, pIndent: string, pKey: string, pVal: string, - pEnd: string) { +function replacer( + match: string, + pIndent: string, + pKey: string, + pVal: string, + pEnd: string, +) { const key = "<span class=json-key>"; const val = "<span class=json-value>"; const str = "<span class=json-string>"; @@ -36,18 +40,18 @@ function replacer(match: string, pIndent: string, pKey: string, pVal: string, return r + (pEnd || ""); } - function prettyPrint(obj: any) { - const jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg; + const jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/gm; return JSON.stringify(obj, null as any, 3) - .replace(/&/g, "&").replace(/\\"/g, """) - .replace(/</g, "<").replace(/>/g, ">") - .replace(jsonLine, replacer); + .replace(/&/g, "&") + .replace(/\\"/g, """) + .replace(/</g, "<") + .replace(/>/g, ">") + .replace(jsonLine, replacer); } - document.addEventListener("DOMContentLoaded", () => { - chrome.runtime.sendMessage({type: "dump-db"}, (resp) => { + chrome.runtime.sendMessage({ type: "dump-db" }, (resp) => { const el = document.getElementById("dump"); if (!el) { throw Error(); @@ -57,16 +61,18 @@ document.addEventListener("DOMContentLoaded", () => { document.getElementById("download")!.addEventListener("click", (evt) => { console.log("creating download"); const element = document.createElement("a"); - element.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(JSON.stringify(resp))); + element.setAttribute( + "href", + "data:text/plain;charset=utf-8," + + encodeURIComponent(JSON.stringify(resp)), + ); element.setAttribute("download", "wallet-dump.txt"); element.style.display = "none"; document.body.appendChild(element); element.click(); }); - }); - const fileInput = document.getElementById("fileInput")! as HTMLInputElement; fileInput.onchange = (evt) => { if (!fileInput.files || fileInput.files.length !== 1) { @@ -79,9 +85,12 @@ document.addEventListener("DOMContentLoaded", () => { console.log("got file"); const dump = JSON.parse(e.target.result); console.log("parsed contents", dump); - chrome.runtime.sendMessage({ type: "import-db", detail: { dump } }, (resp) => { - alert("loaded"); - }); + chrome.runtime.sendMessage( + { type: "import-db", detail: { dump } }, + (resp) => { + alert("loaded"); + }, + ); }; console.log("reading file", file); fr.readAsText(file); |