@inquirer/password 1.1.14 → 1.1.16

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 CHANGED
@@ -1,24 +1,70 @@
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 input_1 = __importDefault(require("@inquirer/input"));
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
- const password = (config, context) => {
10
- if ('transformer' in config) {
11
- throw new Error('Inquirer password prompt do not support custom transformer function. Use the input prompt instead.');
12
- }
13
- return (0, input_1.default)(Object.assign(Object.assign({}, config), { default: undefined, transformer(str, { isFinal }) {
14
- if (config.mask) {
15
- const maskChar = typeof config.mask === 'string' ? config.mask : '*';
16
- return maskChar.repeat(str.length);
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
- if (!isFinal) {
19
- return `${chalk_1.default.dim('[input is masked]')}${ansi_escapes_1.default.cursorHide}`;
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
- return '';
22
- } }), context);
23
- };
24
- exports.default = password;
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
+ let helpTip;
55
+ if (config.mask) {
56
+ const maskChar = typeof config.mask === 'string' ? config.mask : '*';
57
+ formattedValue = maskChar.repeat(value.length);
58
+ }
59
+ else if (status !== 'done') {
60
+ helpTip = `${chalk_1.default.dim('[input is masked]')}${ansi_escapes_1.default.cursorHide}`;
61
+ }
62
+ if (status === 'done') {
63
+ formattedValue = chalk_1.default.cyan(formattedValue);
64
+ }
65
+ let error = '';
66
+ if (errorMsg) {
67
+ error = chalk_1.default.red(`> ${errorMsg}`);
68
+ }
69
+ return [[prefix, message, formattedValue, helpTip].filter(Boolean).join(' '), error];
70
+ });
@@ -1,8 +1,6 @@
1
- import type { Prompt } from '@inquirer/type';
2
- import input from '@inquirer/input';
3
- type InputConfig = Parameters<typeof input>[0];
4
- type PasswordConfig = Omit<InputConfig, 'transformer' | 'default'> & {
5
- mask?: boolean | string;
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;
@@ -1,23 +1,56 @@
1
- import input from '@inquirer/input';
1
+ import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, } from '@inquirer/core';
2
2
  import chalk from 'chalk';
3
3
  import ansiEscapes from 'ansi-escapes';
4
- const password = (config, context) => {
5
- if ('transformer' in config) {
6
- throw new Error('Inquirer password prompt do not support custom transformer function. Use the input prompt instead.');
7
- }
8
- return input({
9
- ...config,
10
- default: undefined,
11
- transformer(str, { isFinal }) {
12
- if (config.mask) {
13
- const maskChar = typeof config.mask === 'string' ? config.mask : '*';
14
- return maskChar.repeat(str.length);
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
- if (!isFinal) {
17
- return `${chalk.dim('[input is masked]')}${ansiEscapes.cursorHide}`;
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
- return '';
20
- },
21
- }, context);
22
- };
23
- export default password;
32
+ }
33
+ else {
34
+ setValue(rl.line);
35
+ setError(undefined);
36
+ }
37
+ });
38
+ const message = chalk.bold(config.message);
39
+ let formattedValue = '';
40
+ let helpTip;
41
+ if (config.mask) {
42
+ const maskChar = typeof config.mask === 'string' ? config.mask : '*';
43
+ formattedValue = maskChar.repeat(value.length);
44
+ }
45
+ else if (status !== 'done') {
46
+ helpTip = `${chalk.dim('[input is masked]')}${ansiEscapes.cursorHide}`;
47
+ }
48
+ if (status === 'done') {
49
+ formattedValue = chalk.cyan(formattedValue);
50
+ }
51
+ let error = '';
52
+ if (errorMsg) {
53
+ error = chalk.red(`> ${errorMsg}`);
54
+ }
55
+ return [[prefix, message, formattedValue, helpTip].filter(Boolean).join(' '), error];
56
+ });
@@ -1,8 +1,6 @@
1
- import type { Prompt } from '@inquirer/type';
2
- import input from '@inquirer/input';
3
- type InputConfig = Parameters<typeof input>[0];
4
- type PasswordConfig = Omit<InputConfig, 'transformer' | 'default'> & {
5
- mask?: boolean | string;
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.14",
3
+ "version": "1.1.16",
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/input": "^1.2.14",
61
- "@inquirer/type": "^1.1.5",
60
+ "@inquirer/core": "^6.0.0",
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.9"
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": "a318aec57d33b53131c0b03cc8dd6ab4efae3e50"
88
+ "gitHead": "4dee2b11d89a7c8a698c9eeda546ba8092b84f64"
89
89
  }