Skip to content

Instantly share code, notes, and snippets.

@exceedsystem
Last active July 3, 2022 23:07
Show Gist options
  • Save exceedsystem/a61635c60e6111549bb01363f5000c07 to your computer and use it in GitHub Desktop.
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
// [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