mirror of
https://github.com/nyanotech/recombobulator
synced 2026-02-08 13:47:28 -08:00
Add a rot13 command
This commit is contained in:
10
package.json
10
package.json
@@ -18,6 +18,7 @@
|
|||||||
},
|
},
|
||||||
"activationEvents": [
|
"activationEvents": [
|
||||||
"onCommand:recombobulator.base64",
|
"onCommand:recombobulator.base64",
|
||||||
|
"onCommand:recombobulator.rot13",
|
||||||
"onCommand:recombobulator.unbase64"
|
"onCommand:recombobulator.unbase64"
|
||||||
],
|
],
|
||||||
"contributes": {
|
"contributes": {
|
||||||
@@ -27,6 +28,11 @@
|
|||||||
"category": "Recombobulator",
|
"category": "Recombobulator",
|
||||||
"title": "base64 encode"
|
"title": "base64 encode"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "recombobulator.rot13",
|
||||||
|
"category": "Recombobulator",
|
||||||
|
"title": "rot13"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "recombobulator.unbase64",
|
"command": "recombobulator.unbase64",
|
||||||
"category": "Recombobulator",
|
"category": "Recombobulator",
|
||||||
@@ -39,6 +45,10 @@
|
|||||||
"command": "recombobulator.base64",
|
"command": "recombobulator.base64",
|
||||||
"when": "editorHasSelection"
|
"when": "editorHasSelection"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "recombobulator.rot13",
|
||||||
|
"when": "editorHasSelection"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "recombobulator.unbase64",
|
"command": "recombobulator.unbase64",
|
||||||
"when": "editorHasSelection"
|
"when": "editorHasSelection"
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ function unbase64(a: string) {
|
|||||||
return Buffer.from(a, 'base64').toString("utf-8"); // TODO - handle different character encodings
|
return Buffer.from(a, 'base64').toString("utf-8"); // TODO - handle different character encodings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function rot13(a: string) {
|
||||||
|
const alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
const rotatedAlphabet = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM";
|
||||||
|
return a.replace(/[a-zA-Z]/g, letter => rotatedAlphabet[alphabet.indexOf(letter)]);
|
||||||
|
}
|
||||||
|
|
||||||
function applyEdit(transform: Function) {
|
function applyEdit(transform: Function) {
|
||||||
const editor = vscode.window.activeTextEditor;
|
const editor = vscode.window.activeTextEditor;
|
||||||
|
|
||||||
@@ -31,6 +37,10 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
applyEdit(base64);
|
applyEdit(base64);
|
||||||
vscode.window.showInformationMessage('base64-encoded the selection!');
|
vscode.window.showInformationMessage('base64-encoded the selection!');
|
||||||
}));
|
}));
|
||||||
|
context.subscriptions.push(vscode.commands.registerCommand('recombobulator.rot13', () => {
|
||||||
|
applyEdit(rot13);
|
||||||
|
vscode.window.showInformationMessage('rot13\'d the selection!');
|
||||||
|
}));
|
||||||
context.subscriptions.push(vscode.commands.registerCommand('recombobulator.unbase64', () => {
|
context.subscriptions.push(vscode.commands.registerCommand('recombobulator.unbase64', () => {
|
||||||
applyEdit(unbase64);
|
applyEdit(unbase64);
|
||||||
vscode.window.showInformationMessage('base64-decoded the selection!');
|
vscode.window.showInformationMessage('base64-decoded the selection!');
|
||||||
|
|||||||
Reference in New Issue
Block a user