Last active
July 3, 2022 23:07
-
-
Save exceedsystem/a61635c60e6111549bb01363f5000c07 to your computer and use it in GitHub Desktop.
An example of 'Insert Random ID using Node.js' macro for VSCodeMacros extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [VSCode Macros] extension | |
// https://marketplace.visualstudio.com/items?itemName=EXCEEDSYSTEM.vscode-macros | |
// License:MIT | |
const vscode = require('vscode'); | |
const crptrndstr = require('crypto-random-string'); | |
module.exports.macroCommands = { | |
InsertRandomID: { | |
no: 1, | |
func: insertRandomId, | |
}, | |
}; | |
function insertRandomId() { | |
const editor = vscode.window.activeTextEditor; | |
if (!editor) { | |
return 'Editor is not opening.'; | |
} | |
const rndStr = crptrndstr({ | |
length: 8, | |
type: 'alphanumeric', | |
}); | |
editor.edit((editBuilder) => { | |
editBuilder.insert(editor.selection.active, rndStr); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment