@inquirer/input 2.1.11 → 2.2.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/README.md CHANGED
@@ -6,12 +6,29 @@ Interactive free text input component for command line interfaces. Supports vali
6
6
 
7
7
  # Installation
8
8
 
9
+ <table>
10
+ <tr>
11
+ <th>npm</th>
12
+ <th>yarn</th>
13
+ </tr>
14
+ <tr>
15
+ <td>
16
+
9
17
  ```sh
10
18
  npm install @inquirer/input
19
+ ```
20
+
21
+ </td>
22
+ <td>
11
23
 
24
+ ```sh
12
25
  yarn add @inquirer/input
13
26
  ```
14
27
 
28
+ </td>
29
+ </tr>
30
+ </table>
31
+
15
32
  # Usage
16
33
 
17
34
  ```js
@@ -27,7 +44,7 @@ const answer = await input({ message: 'Enter your name' });
27
44
  | message | `string` | yes | The question to ask |
28
45
  | default | `string` | no | Default value if no answer is provided (clear it by pressing backspace) |
29
46
  | transformer | `(string, { isFinal: boolean }) => string` | no | Transform/Format the raw value entered by the user. Once the prompt is completed, `isFinal` will be `true`. This function is purely visual, modify the answer in your code if needed. |
30
- | 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. |
47
+ | validate | `string => boolean \| string \| Promise<boolean \| string>` | 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. |
31
48
  | theme | [See Theming](#Theming) | no | Customize look of the prompt. |
32
49
 
33
50
  ## Theming
package/dist/cjs/index.js CHANGED
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const core_1 = require("@inquirer/core");
13
13
  exports.default = (0, core_1.createPrompt)((config, done) => {
14
- const { validate = () => true } = config;
14
+ const { required, validate = () => true } = config;
15
15
  const theme = (0, core_1.makeTheme)(config.theme);
16
16
  const [status, setStatus] = (0, core_1.useState)('pending');
17
17
  const [defaultValue = '', setDefaultValue] = (0, core_1.useState)(config.default);
@@ -27,7 +27,7 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
27
27
  if ((0, core_1.isEnterKey)(key)) {
28
28
  const answer = value || defaultValue;
29
29
  setStatus('loading');
30
- const isValid = yield validate(answer);
30
+ const isValid = required && !answer ? 'You must provide a value' : yield validate(answer);
31
31
  if (isValid === true) {
32
32
  setValue(answer);
33
33
  setStatus('done');
@@ -3,6 +3,7 @@ import type { PartialDeep } from '@inquirer/type';
3
3
  type InputConfig = {
4
4
  message: string;
5
5
  default?: string;
6
+ required?: boolean;
6
7
  transformer?: (value: string, { isFinal }: {
7
8
  isFinal: boolean;
8
9
  }) => string;
@@ -1,6 +1,6 @@
1
1
  import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, isBackspaceKey, makeTheme, } from '@inquirer/core';
2
2
  export default createPrompt((config, done) => {
3
- const { validate = () => true } = config;
3
+ const { required, validate = () => true } = config;
4
4
  const theme = makeTheme(config.theme);
5
5
  const [status, setStatus] = useState('pending');
6
6
  const [defaultValue = '', setDefaultValue] = useState(config.default);
@@ -16,7 +16,7 @@ export default createPrompt((config, done) => {
16
16
  if (isEnterKey(key)) {
17
17
  const answer = value || defaultValue;
18
18
  setStatus('loading');
19
- const isValid = await validate(answer);
19
+ const isValid = required && !answer ? 'You must provide a value' : await validate(answer);
20
20
  if (isValid === true) {
21
21
  setValue(answer);
22
22
  setStatus('done');
@@ -3,6 +3,7 @@ import type { PartialDeep } from '@inquirer/type';
3
3
  type InputConfig = {
4
4
  message: string;
5
5
  default?: string;
6
+ required?: boolean;
6
7
  transformer?: (value: string, { isFinal }: {
7
8
  isFinal: boolean;
8
9
  }) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/input",
3
- "version": "2.1.11",
3
+ "version": "2.2.0",
4
4
  "description": "Inquirer input text prompt",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "typings": "./dist/cjs/types/index.d.ts",
@@ -54,11 +54,11 @@
54
54
  "license": "MIT",
55
55
  "homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/input/README.md",
56
56
  "dependencies": {
57
- "@inquirer/core": "^8.2.4",
58
- "@inquirer/type": "^1.3.3"
57
+ "@inquirer/core": "^9.0.1",
58
+ "@inquirer/type": "^1.4.0"
59
59
  },
60
60
  "devDependencies": {
61
- "@inquirer/testing": "^2.1.23"
61
+ "@inquirer/testing": "^2.1.25"
62
62
  },
63
63
  "scripts": {
64
64
  "tsc": "yarn run tsc:esm && yarn run tsc:cjs",
@@ -86,5 +86,5 @@
86
86
  }
87
87
  },
88
88
  "sideEffects": false,
89
- "gitHead": "d5f62c6ee3e671f7d1b776b85d43781869d70918"
89
+ "gitHead": "2285f2c043448ff4317635cf6481df7ffda2d3bd"
90
90
  }