Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JustHxnry committed Sep 27, 2022
0 parents commit 7f509c7
Show file tree
Hide file tree
Showing 4 changed files with 262 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
85 changes: 85 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env node

const chalk = require('chalk');

const rl = require('readline');

const randoms = require('@justhxnry/randoms');

// usage function to represent help guide
const usage = function() {
const usageText = `
Password Generator in Command Line Interface is fast, secure and customizable.
usage:
pwgen
`;

console.log(usageText);
};

// log errors with red color
function errorLog(error) {
const eLog = chalk.red(error);
console.log(eLog);
};

// log successfull request with white color
function successLog(data) {
const sLog = chalk.whiteBright(data);
console.log(sLog);
};

// prompts
function prompt(question) {
const r = rl.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
return new Promise((resolve, reject) => {
try {
r.question(question, answer => {
r.close();
resolve(answer);
});
} catch (e) {
reject(e);
}
});
};

function main() {
let q = chalk.blue(`Custom password string: `);
prompt(q).then(string => {
if (!string) string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

q = chalk.blue(`Enter password length: `);
prompt(q).then(dlength => {

if (!dlength) {
errorLog(`Password Length is required parameter, recieved null`);
return usage();
};

try {
length = Number(dlength);

if (isNaN(length)) {
errorLog(`Password Length must be a number, recieved "${dlength}"`);
return usage();
};

var password = randoms.random(string, length);

var response = `Your generated password: \n\n ${password}\n`;

successLog(response);
} catch (e) {
errorLog(`Password Length must be a number, recieved "${length}"`);
return usage();
}
});
})
};
main();
147 changes: 147 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "pwgen-cli",
"version": "1.0.0",
"description": "Program to generate random password",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/JustHxnry/pwgen-cli.git"
},
"keywords": [
"passwordgenerator",
"generator",
"cli"
],
"author": "JustHxnry",
"license": "ISC",
"bugs": {
"url": "https://github.com/JustHxnry/pwgen-cli/issues"
},
"homepage": "https://github.com/JustHxnry/pwgen-cli#readme",
"dependencies": {
"@justhxnry/randoms": "^1.0.1",
"chalk": "^4.1.2",
"readline": "^1.3.0"
}
}

0 comments on commit 7f509c7

Please sign in to comment.