@inquirer/password 1.1.16 → 2.0.1

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/README.md CHANGED
@@ -27,6 +27,27 @@ const answer = await password({ message: 'Enter your name' });
27
27
  | message | `string` | yes | The question to ask |
28
28
  | mask | `boolean` | no | Show a `*` mask over the input or keep it transparent |
29
29
  | validate | `string => boolean \| string \| Promise<string \| boolean>` | no | On submit, validate the filtered answered content. When returning a string, it'll be used as the error message displayed to the user. Note: returning a rejected promise, we'll assume a code error happened and crash. |
30
+ | theme | [See Theming](#Theming) | no | Customize look of the prompt. |
31
+
32
+ ## Theming
33
+
34
+ You can theme a prompt by passing a `theme` object option. The theme object only need to includes the keys you wish to modify, we'll fallback on the defaults for the rest.
35
+
36
+ ```ts
37
+ type Theme = {
38
+ prefix: string;
39
+ spinner: {
40
+ interval: number;
41
+ frames: string[];
42
+ };
43
+ style: {
44
+ answer: (text: string) => string;
45
+ message: (text: string) => string;
46
+ error: (text: string) => string;
47
+ help: (text: string) => string;
48
+ };
49
+ };
50
+ ```
30
51
 
31
52
  # License
32
53
 
package/dist/cjs/index.js CHANGED
@@ -13,15 +13,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const core_1 = require("@inquirer/core");
16
- const chalk_1 = __importDefault(require("chalk"));
17
16
  const ansi_escapes_1 = __importDefault(require("ansi-escapes"));
18
17
  exports.default = (0, core_1.createPrompt)((config, done) => {
19
18
  const { validate = () => true } = config;
19
+ const theme = (0, core_1.makeTheme)(config.theme);
20
20
  const [status, setStatus] = (0, core_1.useState)('pending');
21
21
  const [errorMsg, setError] = (0, core_1.useState)(undefined);
22
22
  const [value, setValue] = (0, core_1.useState)('');
23
23
  const isLoading = status === 'loading';
24
- const prefix = (0, core_1.usePrefix)(isLoading);
24
+ const prefix = (0, core_1.usePrefix)({ isLoading, theme });
25
25
  (0, core_1.useKeypress)((key, rl) => __awaiter(void 0, void 0, void 0, function* () {
26
26
  // Ignore keypress while our prompt is doing other processing.
27
27
  if (status !== 'pending') {
@@ -49,7 +49,7 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
49
49
  setError(undefined);
50
50
  }
51
51
  }));
52
- const message = chalk_1.default.bold(config.message);
52
+ const message = theme.style.message(config.message);
53
53
  let formattedValue = '';
54
54
  let helpTip;
55
55
  if (config.mask) {
@@ -57,14 +57,14 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
57
57
  formattedValue = maskChar.repeat(value.length);
58
58
  }
59
59
  else if (status !== 'done') {
60
- helpTip = `${chalk_1.default.dim('[input is masked]')}${ansi_escapes_1.default.cursorHide}`;
60
+ helpTip = `${theme.style.help('[input is masked]')}${ansi_escapes_1.default.cursorHide}`;
61
61
  }
62
62
  if (status === 'done') {
63
- formattedValue = chalk_1.default.cyan(formattedValue);
63
+ formattedValue = theme.style.answer(formattedValue);
64
64
  }
65
65
  let error = '';
66
66
  if (errorMsg) {
67
- error = chalk_1.default.red(`> ${errorMsg}`);
67
+ error = theme.style.error(errorMsg);
68
68
  }
69
69
  return [[prefix, message, formattedValue, helpTip].filter(Boolean).join(' '), error];
70
70
  });
@@ -1,6 +1,10 @@
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
- }>;
1
+ import { type Theme } from '@inquirer/core';
2
+ import type { PartialDeep } from '@inquirer/type';
3
+ type PasswordConfig = {
4
+ message: string;
5
+ mask?: boolean | string;
6
+ validate?: (value: string) => boolean | string | Promise<string | boolean>;
7
+ theme?: PartialDeep<Theme>;
8
+ };
9
+ declare const _default: import("@inquirer/type").Prompt<string, PasswordConfig>;
6
10
  export default _default;
@@ -1,13 +1,13 @@
1
- import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, } from '@inquirer/core';
2
- import chalk from 'chalk';
1
+ import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, makeTheme, } from '@inquirer/core';
3
2
  import ansiEscapes from 'ansi-escapes';
4
3
  export default createPrompt((config, done) => {
5
4
  const { validate = () => true } = config;
5
+ const theme = makeTheme(config.theme);
6
6
  const [status, setStatus] = useState('pending');
7
7
  const [errorMsg, setError] = useState(undefined);
8
8
  const [value, setValue] = useState('');
9
9
  const isLoading = status === 'loading';
10
- const prefix = usePrefix(isLoading);
10
+ const prefix = usePrefix({ isLoading, theme });
11
11
  useKeypress(async (key, rl) => {
12
12
  // Ignore keypress while our prompt is doing other processing.
13
13
  if (status !== 'pending') {
@@ -35,7 +35,7 @@ export default createPrompt((config, done) => {
35
35
  setError(undefined);
36
36
  }
37
37
  });
38
- const message = chalk.bold(config.message);
38
+ const message = theme.style.message(config.message);
39
39
  let formattedValue = '';
40
40
  let helpTip;
41
41
  if (config.mask) {
@@ -43,14 +43,14 @@ export default createPrompt((config, done) => {
43
43
  formattedValue = maskChar.repeat(value.length);
44
44
  }
45
45
  else if (status !== 'done') {
46
- helpTip = `${chalk.dim('[input is masked]')}${ansiEscapes.cursorHide}`;
46
+ helpTip = `${theme.style.help('[input is masked]')}${ansiEscapes.cursorHide}`;
47
47
  }
48
48
  if (status === 'done') {
49
- formattedValue = chalk.cyan(formattedValue);
49
+ formattedValue = theme.style.answer(formattedValue);
50
50
  }
51
51
  let error = '';
52
52
  if (errorMsg) {
53
- error = chalk.red(`> ${errorMsg}`);
53
+ error = theme.style.error(errorMsg);
54
54
  }
55
55
  return [[prefix, message, formattedValue, helpTip].filter(Boolean).join(' '), error];
56
56
  });
@@ -1,6 +1,10 @@
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
- }>;
1
+ import { type Theme } from '@inquirer/core';
2
+ import type { PartialDeep } from '@inquirer/type';
3
+ type PasswordConfig = {
4
+ message: string;
5
+ mask?: boolean | string;
6
+ validate?: (value: string) => boolean | string | Promise<string | boolean>;
7
+ theme?: PartialDeep<Theme>;
8
+ };
9
+ declare const _default: import("@inquirer/type").Prompt<string, PasswordConfig>;
6
10
  export default _default;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@inquirer/password",
3
- "version": "1.1.16",
3
+ "version": "2.0.1",
4
4
  "engines": {
5
- "node": ">=14.18.0"
5
+ "node": ">=18"
6
6
  },
7
7
  "description": "Inquirer password prompt",
8
8
  "main": "./dist/cjs/index.js",
@@ -57,13 +57,12 @@
57
57
  "license": "MIT",
58
58
  "homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/password/README.md",
59
59
  "dependencies": {
60
- "@inquirer/core": "^6.0.0",
61
- "@inquirer/type": "^1.1.6",
62
- "ansi-escapes": "^4.3.2",
63
- "chalk": "^4.1.2"
60
+ "@inquirer/core": "^7.0.1",
61
+ "@inquirer/type": "^1.2.0",
62
+ "ansi-escapes": "^4.3.2"
64
63
  },
65
64
  "devDependencies": {
66
- "@inquirer/testing": "^2.1.10"
65
+ "@inquirer/testing": "^2.1.12"
67
66
  },
68
67
  "scripts": {
69
68
  "tsc": "yarn run tsc:esm && yarn run tsc:cjs",
@@ -85,5 +84,5 @@
85
84
  }
86
85
  }
87
86
  },
88
- "gitHead": "4dee2b11d89a7c8a698c9eeda546ba8092b84f64"
87
+ "gitHead": "c91196e66689cfc05e9237763e6f95f3eb5342a1"
89
88
  }