-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
路43 lines (35 loc) 路 1.33 KB
/
index.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
#!/usr/bin/env node
import { program } from "commander";
import chalk from "chalk";
import clipboard from "clipboardy";
const log = console.log;
import { createAPassword } from "./utils/createPassword.js";
import { savePassword } from "./utils/savePassword.js";
import figlet from "figlet";
const styledDescriptionText = chalk.green(
figlet.textSync("Password Generator", {
font: "Standard",
horizontalLayout: "default",
verticalLayout: "default",
width: 100,
whitespaceBreak: false,
})
)
program.version("1.0.0").description(styledDescriptionText);
program
.option("-l, --length <number>", "length of password", "8")
.option("-s, --save", "save password to password.txt")
.option("-nn, --no-numbers", "remove numbers")
.option("-ns, --no-symbols", "remove symbols")
.parse();
// Values of above provides options length is 8 by default and others are 'true'
const { length, save, numbers, symbols } = program.opts();
// Get generated password
const generatedPassword = createAPassword(length, numbers, symbols);
// To save password to file
if (save) savePassword(generatedPassword);
// Copy to clipboard
clipboard.writeSync(generatedPassword);
// Output the generated password
log(chalk.blue("Generated Password is: ") + chalk.bold(generatedPassword));
log(chalk.yellow("Password copied to clipboard"));