From cd85661f8da69026784d1d88ce65896af60d8121 Mon Sep 17 00:00:00 2001 From: nyanotech Date: Wed, 23 Mar 2022 10:58:36 +0000 Subject: [PATCH] Add an un-base64 command --- package.json | 12 +++++++++++- src/extension.ts | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 45d0478..18e2eb8 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ } }, "activationEvents": [ - "onCommand:recombobulator.base64" + "onCommand:recombobulator.base64", + "onCommand:recombobulator.unbase64" ], "contributes": { "commands": [ @@ -25,6 +26,11 @@ "command": "recombobulator.base64", "category": "Recombobulator", "title": "base64 encode" + }, + { + "command": "recombobulator.unbase64", + "category": "Recombobulator", + "title": "base64 decode" } ], "menus": { @@ -32,6 +38,10 @@ { "command": "recombobulator.base64", "when": "editorHasSelection" + }, + { + "command": "recombobulator.unbase64", + "when": "editorHasSelection" } ] } diff --git a/src/extension.ts b/src/extension.ts index e7d5364..2888513 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -4,6 +4,10 @@ function base64(a: string) { return Buffer.from(a).toString('base64'); // TODO - handle different character encodings } +function unbase64(a: string) { + return Buffer.from(a, 'base64').toString("utf-8"); // TODO - handle different character encodings +} + function applyEdit(transform: Function) { const editor = vscode.window.activeTextEditor; @@ -27,4 +31,8 @@ export function activate(context: vscode.ExtensionContext) { applyEdit(base64); vscode.window.showInformationMessage('base64-encoded the selection!'); })); + context.subscriptions.push(vscode.commands.registerCommand('recombobulator.unbase64', () => { + applyEdit(unbase64); + vscode.window.showInformationMessage('base64-decoded the selection!'); + })); }