-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
46 lines (39 loc) · 1.13 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const vscode = require('vscode');
const cpf = require("@fnando/cpf/dist/node");
const cnpj = require("@fnando/cnpj/dist/node");
function activate(context) {
var commands = [
vscode.commands.registerCommand('br-tax-id-generator.cnpj', generateCNPJ),
vscode.commands.registerCommand('br-tax-id-generator.cpf', generateCPF)
];
commands.forEach(function (command) {
context.subscriptions.push(command);
});
}
function insertText(text) {
var editor = vscode.window.activeTextEditor;
editor.edit(
edit => editor.selections.forEach(
selection => {
edit.delete(selection);
edit.insert(selection.start, text);
}
)
);
}
const options = [{label: "Yes", picked: true}, {label: "No"}]
const showQuickPickOptions = [options, { placeHolder: 'Only digits?' }]
function generateCNPJ() {
generate(cnpj.generate);
}
function generateCPF() {
generate(cpf.generate);
}
function generate(generator) {
vscode.window.showQuickPick(...showQuickPickOptions)
.then(selection => {
if (!selection) return;
insertText(generator(selection.label === 'No'));
});
}
exports.activate = activate;