@vexify-org/yaggs 6.11.0 → 6.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -173,6 +173,10 @@ class Yaggs {
173
173
  return this.parser.select(options, question);
174
174
  }
175
175
 
176
+ async password(message = 'Enter password') {
177
+ return this.parser.password(message);
178
+ }
179
+
176
180
  check(fn) {
177
181
  this.middleware(fn);
178
182
  return this;
package/lib/parser.js CHANGED
@@ -1011,6 +1011,50 @@ complete -c ${this.scriptName} `;
1011
1011
  });
1012
1012
  }
1013
1013
 
1014
+ async password(message = 'Enter password') {
1015
+ const readline = require('readline');
1016
+ const rl = readline.createInterface({
1017
+ input: process.stdin,
1018
+ output: process.stdout,
1019
+ terminal: true
1020
+ });
1021
+
1022
+ return new Promise((resolve) => {
1023
+ const stdin = process.stdin;
1024
+ const stdout = process.stdout;
1025
+
1026
+ stdin.setRawMode(true);
1027
+
1028
+ let password = '';
1029
+
1030
+ stdout.write(`\u001b[34m${message}:\u001b[0m `);
1031
+
1032
+ const onData = (data) => {
1033
+ const char = data.toString('utf8');
1034
+
1035
+ if (char === '\n' || char === '\r') {
1036
+ stdin.setRawMode(false);
1037
+ stdout.write('\n');
1038
+ stdin.removeListener('data', onData);
1039
+ rl.close();
1040
+ resolve(password);
1041
+ } else if (char === '\u0008' || char === '\u007f') {
1042
+ if (password.length > 0) {
1043
+ password = password.slice(0, -1);
1044
+ stdout.write('\u0008 \u0008');
1045
+ }
1046
+ } else if (char.charCodeAt(0) === 3) {
1047
+ process.exit(1);
1048
+ } else {
1049
+ password += char;
1050
+ stdout.write('*');
1051
+ }
1052
+ };
1053
+
1054
+ stdin.on('data', onData);
1055
+ });
1056
+ }
1057
+
1014
1058
  getHelp() {
1015
1059
  let help = `\u001b[36m${this.scriptName}\u001b[0m`;
1016
1060
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vexify-org/yaggs",
3
- "version": "6.11.0",
3
+ "version": "6.12.0",
4
4
  "description": "A powerful CLI argument parser, better than yargs",
5
5
  "main": "index.js",
6
6
  "scripts": {