Add an un-base64 command

This commit is contained in:
nyanotech 2022-03-23 10:58:36 +00:00
parent a6157d0a16
commit cd85661f8d
Signed by: nyanotech
GPG Key ID: D2D0A9E8F160472B
2 changed files with 19 additions and 1 deletions

View File

@ -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"
}
]
}

View File

@ -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!');
}));
}