@inquirer/password 1.1.14 → 1.1.15
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/dist/cjs/index.js +60 -15
- package/dist/cjs/types/index.d.ts +6 -8
- package/dist/esm/index.mjs +51 -19
- package/dist/esm/types/index.d.mts +6 -8
- package/package.json +5 -5
package/dist/cjs/index.js
CHANGED
|
@@ -1,24 +1,69 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
5
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
15
|
+
const core_1 = require("@inquirer/core");
|
|
7
16
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
17
|
const ansi_escapes_1 = __importDefault(require("ansi-escapes"));
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
19
|
+
const { validate = () => true } = config;
|
|
20
|
+
const [status, setStatus] = (0, core_1.useState)('pending');
|
|
21
|
+
const [errorMsg, setError] = (0, core_1.useState)(undefined);
|
|
22
|
+
const [value, setValue] = (0, core_1.useState)('');
|
|
23
|
+
const isLoading = status === 'loading';
|
|
24
|
+
const prefix = (0, core_1.usePrefix)(isLoading);
|
|
25
|
+
(0, core_1.useKeypress)((key, rl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
// Ignore keypress while our prompt is doing other processing.
|
|
27
|
+
if (status !== 'pending') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if ((0, core_1.isEnterKey)(key)) {
|
|
31
|
+
const answer = value;
|
|
32
|
+
setStatus('loading');
|
|
33
|
+
const isValid = yield validate(answer);
|
|
34
|
+
if (isValid === true) {
|
|
35
|
+
setValue(answer);
|
|
36
|
+
setStatus('done');
|
|
37
|
+
done(answer);
|
|
17
38
|
}
|
|
18
|
-
|
|
19
|
-
|
|
39
|
+
else {
|
|
40
|
+
// Reset the readline line value to the previous value. On line event, the value
|
|
41
|
+
// get cleared, forcing the user to re-enter the value instead of fixing it.
|
|
42
|
+
rl.write(value);
|
|
43
|
+
setError(isValid || 'You must provide a valid value');
|
|
44
|
+
setStatus('pending');
|
|
20
45
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
setValue(rl.line);
|
|
49
|
+
setError(undefined);
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
const message = chalk_1.default.bold(config.message);
|
|
53
|
+
let formattedValue = '';
|
|
54
|
+
if (config.mask) {
|
|
55
|
+
const maskChar = typeof config.mask === 'string' ? config.mask : '*';
|
|
56
|
+
formattedValue = maskChar.repeat(value.length);
|
|
57
|
+
}
|
|
58
|
+
else if (status !== 'done') {
|
|
59
|
+
formattedValue = `${chalk_1.default.dim('[input is masked]')}${ansi_escapes_1.default.cursorHide}`;
|
|
60
|
+
}
|
|
61
|
+
if (status === 'done') {
|
|
62
|
+
formattedValue = chalk_1.default.cyan(formattedValue);
|
|
63
|
+
}
|
|
64
|
+
let error = '';
|
|
65
|
+
if (errorMsg) {
|
|
66
|
+
error = chalk_1.default.red(`> ${errorMsg}`);
|
|
67
|
+
}
|
|
68
|
+
return [`${prefix} ${message} ${formattedValue}`, error];
|
|
69
|
+
});
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
declare const password: Prompt<string, PasswordConfig>;
|
|
8
|
-
export default password;
|
|
1
|
+
declare const _default: import("@inquirer/type").Prompt<string, {
|
|
2
|
+
message: string | Promise<string> | (() => Promise<string>);
|
|
3
|
+
mask?: string | boolean | undefined;
|
|
4
|
+
validate?: ((value: string) => string | boolean | Promise<string | boolean>) | undefined;
|
|
5
|
+
}>;
|
|
6
|
+
export default _default;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,23 +1,55 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, } from '@inquirer/core';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import ansiEscapes from 'ansi-escapes';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
export default createPrompt((config, done) => {
|
|
5
|
+
const { validate = () => true } = config;
|
|
6
|
+
const [status, setStatus] = useState('pending');
|
|
7
|
+
const [errorMsg, setError] = useState(undefined);
|
|
8
|
+
const [value, setValue] = useState('');
|
|
9
|
+
const isLoading = status === 'loading';
|
|
10
|
+
const prefix = usePrefix(isLoading);
|
|
11
|
+
useKeypress(async (key, rl) => {
|
|
12
|
+
// Ignore keypress while our prompt is doing other processing.
|
|
13
|
+
if (status !== 'pending') {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (isEnterKey(key)) {
|
|
17
|
+
const answer = value;
|
|
18
|
+
setStatus('loading');
|
|
19
|
+
const isValid = await validate(answer);
|
|
20
|
+
if (isValid === true) {
|
|
21
|
+
setValue(answer);
|
|
22
|
+
setStatus('done');
|
|
23
|
+
done(answer);
|
|
15
24
|
}
|
|
16
|
-
|
|
17
|
-
|
|
25
|
+
else {
|
|
26
|
+
// Reset the readline line value to the previous value. On line event, the value
|
|
27
|
+
// get cleared, forcing the user to re-enter the value instead of fixing it.
|
|
28
|
+
rl.write(value);
|
|
29
|
+
setError(isValid || 'You must provide a valid value');
|
|
30
|
+
setStatus('pending');
|
|
18
31
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
setValue(rl.line);
|
|
35
|
+
setError(undefined);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const message = chalk.bold(config.message);
|
|
39
|
+
let formattedValue = '';
|
|
40
|
+
if (config.mask) {
|
|
41
|
+
const maskChar = typeof config.mask === 'string' ? config.mask : '*';
|
|
42
|
+
formattedValue = maskChar.repeat(value.length);
|
|
43
|
+
}
|
|
44
|
+
else if (status !== 'done') {
|
|
45
|
+
formattedValue = `${chalk.dim('[input is masked]')}${ansiEscapes.cursorHide}`;
|
|
46
|
+
}
|
|
47
|
+
if (status === 'done') {
|
|
48
|
+
formattedValue = chalk.cyan(formattedValue);
|
|
49
|
+
}
|
|
50
|
+
let error = '';
|
|
51
|
+
if (errorMsg) {
|
|
52
|
+
error = chalk.red(`> ${errorMsg}`);
|
|
53
|
+
}
|
|
54
|
+
return [`${prefix} ${message} ${formattedValue}`, error];
|
|
55
|
+
});
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
declare const password: Prompt<string, PasswordConfig>;
|
|
8
|
-
export default password;
|
|
1
|
+
declare const _default: import("@inquirer/type").Prompt<string, {
|
|
2
|
+
message: string | Promise<string> | (() => Promise<string>);
|
|
3
|
+
mask?: string | boolean | undefined;
|
|
4
|
+
validate?: ((value: string) => string | boolean | Promise<string | boolean>) | undefined;
|
|
5
|
+
}>;
|
|
6
|
+
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/password",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.15",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=14.18.0"
|
|
6
6
|
},
|
|
@@ -57,13 +57,13 @@
|
|
|
57
57
|
"license": "MIT",
|
|
58
58
|
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/password/README.md",
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@inquirer/
|
|
61
|
-
"@inquirer/type": "^1.1.
|
|
60
|
+
"@inquirer/core": "^5.1.2",
|
|
61
|
+
"@inquirer/type": "^1.1.6",
|
|
62
62
|
"ansi-escapes": "^4.3.2",
|
|
63
63
|
"chalk": "^4.1.2"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@inquirer/testing": "^2.1.
|
|
66
|
+
"@inquirer/testing": "^2.1.10"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"tsc": "yarn run tsc:esm && yarn run tsc:cjs",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "6c0d1d23e6881a10bc3d718d079a0a09ba382dd5"
|
|
89
89
|
}
|