@inquirer/input 2.1.12 → 2.2.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 +18 -0
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/types/index.d.mts +1 -0
- package/dist/types/index.d.ts +14 -0
- package/package.json +4 -4
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
|
|
@@ -26,6 +43,7 @@ const answer = await input({ message: 'Enter your name' });
|
|
|
26
43
|
| ----------- | ----------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
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) |
|
|
46
|
+
| required | `boolean` | no | Defaults to `false`. If set to true, `undefined` (empty) will not be accepted for this. |
|
|
29
47
|
| 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
48
|
| 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
49
|
| theme | [See Theming](#Theming) | no | Customize look of the prompt. |
|
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');
|
package/dist/esm/index.mjs
CHANGED
|
@@ -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');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Theme } from '@inquirer/core';
|
|
2
|
+
import type { PartialDeep } from '@inquirer/type';
|
|
3
|
+
type InputConfig = {
|
|
4
|
+
message: string;
|
|
5
|
+
default?: string;
|
|
6
|
+
required?: boolean;
|
|
7
|
+
transformer?: (value: string, { isFinal }: {
|
|
8
|
+
isFinal: boolean;
|
|
9
|
+
}) => string;
|
|
10
|
+
validate?: (value: string) => boolean | string | Promise<string | boolean>;
|
|
11
|
+
theme?: PartialDeep<Theme>;
|
|
12
|
+
};
|
|
13
|
+
declare const _default: import("@inquirer/type").Prompt<string, InputConfig>;
|
|
14
|
+
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/input",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
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": "^9.0.
|
|
57
|
+
"@inquirer/core": "^9.0.2",
|
|
58
58
|
"@inquirer/type": "^1.4.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@inquirer/testing": "^2.1.
|
|
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": "
|
|
89
|
+
"gitHead": "95d2d65d3aca2c0fab66c7fd40b5dc413dfc894f"
|
|
90
90
|
}
|