@inquirer/input 1.2.15 → 2.0.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 +21 -0
- package/dist/cjs/index.js +9 -12
- package/dist/cjs/types/index.d.ts +11 -7
- package/dist/esm/index.mjs +10 -10
- package/dist/esm/types/index.d.mts +11 -7
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -28,6 +28,27 @@ const answer = await input({ message: 'Enter your name' });
|
|
|
28
28
|
| default | `string` | no | Default value if no answer is provided (clear it by pressing backspace) |
|
|
29
29
|
| 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
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. |
|
|
31
|
+
| theme | [See Theming](#Theming) | no | Customize look of the prompt. |
|
|
32
|
+
|
|
33
|
+
## Theming
|
|
34
|
+
|
|
35
|
+
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.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
type Theme = {
|
|
39
|
+
prefix: string;
|
|
40
|
+
spinner: {
|
|
41
|
+
interval: number;
|
|
42
|
+
frames: string[];
|
|
43
|
+
};
|
|
44
|
+
style: {
|
|
45
|
+
answer: (text: string) => string;
|
|
46
|
+
message: (text: string) => string;
|
|
47
|
+
error: (text: string) => string;
|
|
48
|
+
defaultAnswer: (text: string) => string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
```
|
|
31
52
|
|
|
32
53
|
# License
|
|
33
54
|
|
package/dist/cjs/index.js
CHANGED
|
@@ -8,20 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
const core_1 = require("@inquirer/core");
|
|
16
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
17
13
|
exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
18
14
|
const { validate = () => true } = config;
|
|
15
|
+
const theme = (0, core_1.makeTheme)(config.theme);
|
|
19
16
|
const [status, setStatus] = (0, core_1.useState)('pending');
|
|
20
17
|
const [defaultValue = '', setDefaultValue] = (0, core_1.useState)(config.default);
|
|
21
18
|
const [errorMsg, setError] = (0, core_1.useState)(undefined);
|
|
22
19
|
const [value, setValue] = (0, core_1.useState)('');
|
|
23
20
|
const isLoading = status === 'loading';
|
|
24
|
-
const prefix = (0, core_1.usePrefix)(isLoading);
|
|
21
|
+
const prefix = (0, core_1.usePrefix)({ isLoading, theme });
|
|
25
22
|
(0, core_1.useKeypress)((key, rl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
23
|
// Ignore keypress while our prompt is doing other processing.
|
|
27
24
|
if (status !== 'pending') {
|
|
@@ -58,21 +55,21 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
58
55
|
setError(undefined);
|
|
59
56
|
}
|
|
60
57
|
}));
|
|
61
|
-
const message =
|
|
58
|
+
const message = theme.style.message(config.message);
|
|
62
59
|
let formattedValue = value;
|
|
63
60
|
if (typeof config.transformer === 'function') {
|
|
64
61
|
formattedValue = config.transformer(value, { isFinal: status === 'done' });
|
|
65
62
|
}
|
|
66
|
-
if (status === 'done') {
|
|
67
|
-
formattedValue =
|
|
63
|
+
else if (status === 'done') {
|
|
64
|
+
formattedValue = theme.style.answer(value);
|
|
68
65
|
}
|
|
69
|
-
let defaultStr
|
|
66
|
+
let defaultStr;
|
|
70
67
|
if (defaultValue && status !== 'done' && !value) {
|
|
71
|
-
defaultStr =
|
|
68
|
+
defaultStr = theme.style.defaultAnswer(defaultValue);
|
|
72
69
|
}
|
|
73
70
|
let error = '';
|
|
74
71
|
if (errorMsg) {
|
|
75
|
-
error =
|
|
72
|
+
error = theme.style.error(errorMsg);
|
|
76
73
|
}
|
|
77
|
-
return [
|
|
74
|
+
return [[prefix, message, defaultStr, formattedValue].filter(Boolean).join(' '), error];
|
|
78
75
|
});
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { type Theme } from '@inquirer/core';
|
|
2
|
+
import type { PartialDeep } from '@inquirer/type';
|
|
3
|
+
type InputConfig = {
|
|
4
|
+
message: string;
|
|
5
|
+
default?: string;
|
|
6
|
+
transformer?: (value: string, { isFinal }: {
|
|
5
7
|
isFinal: boolean;
|
|
6
|
-
}) => string
|
|
7
|
-
validate?: (
|
|
8
|
-
|
|
8
|
+
}) => string;
|
|
9
|
+
validate?: (value: string) => boolean | string | Promise<string | boolean>;
|
|
10
|
+
theme?: PartialDeep<Theme>;
|
|
11
|
+
};
|
|
12
|
+
declare const _default: import("@inquirer/type").Prompt<string, InputConfig>;
|
|
9
13
|
export default _default;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, isBackspaceKey, } from '@inquirer/core';
|
|
2
|
-
import chalk from 'chalk';
|
|
1
|
+
import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, isBackspaceKey, makeTheme, } from '@inquirer/core';
|
|
3
2
|
export default createPrompt((config, done) => {
|
|
4
3
|
const { validate = () => true } = config;
|
|
4
|
+
const theme = makeTheme(config.theme);
|
|
5
5
|
const [status, setStatus] = useState('pending');
|
|
6
6
|
const [defaultValue = '', setDefaultValue] = useState(config.default);
|
|
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') {
|
|
@@ -44,21 +44,21 @@ export default createPrompt((config, done) => {
|
|
|
44
44
|
setError(undefined);
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
|
-
const message =
|
|
47
|
+
const message = theme.style.message(config.message);
|
|
48
48
|
let formattedValue = value;
|
|
49
49
|
if (typeof config.transformer === 'function') {
|
|
50
50
|
formattedValue = config.transformer(value, { isFinal: status === 'done' });
|
|
51
51
|
}
|
|
52
|
-
if (status === 'done') {
|
|
53
|
-
formattedValue =
|
|
52
|
+
else if (status === 'done') {
|
|
53
|
+
formattedValue = theme.style.answer(value);
|
|
54
54
|
}
|
|
55
|
-
let defaultStr
|
|
55
|
+
let defaultStr;
|
|
56
56
|
if (defaultValue && status !== 'done' && !value) {
|
|
57
|
-
defaultStr =
|
|
57
|
+
defaultStr = theme.style.defaultAnswer(defaultValue);
|
|
58
58
|
}
|
|
59
59
|
let error = '';
|
|
60
60
|
if (errorMsg) {
|
|
61
|
-
error =
|
|
61
|
+
error = theme.style.error(errorMsg);
|
|
62
62
|
}
|
|
63
|
-
return [
|
|
63
|
+
return [[prefix, message, defaultStr, formattedValue].filter(Boolean).join(' '), error];
|
|
64
64
|
});
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { type Theme } from '@inquirer/core';
|
|
2
|
+
import type { PartialDeep } from '@inquirer/type';
|
|
3
|
+
type InputConfig = {
|
|
4
|
+
message: string;
|
|
5
|
+
default?: string;
|
|
6
|
+
transformer?: (value: string, { isFinal }: {
|
|
5
7
|
isFinal: boolean;
|
|
6
|
-
}) => string
|
|
7
|
-
validate?: (
|
|
8
|
-
|
|
8
|
+
}) => string;
|
|
9
|
+
validate?: (value: string) => boolean | string | Promise<string | boolean>;
|
|
10
|
+
theme?: PartialDeep<Theme>;
|
|
11
|
+
};
|
|
12
|
+
declare const _default: import("@inquirer/type").Prompt<string, InputConfig>;
|
|
9
13
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/input",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.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,12 +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": "^
|
|
58
|
-
"@inquirer/type": "^1.
|
|
59
|
-
"chalk": "^4.1.2"
|
|
57
|
+
"@inquirer/core": "^7.0.0",
|
|
58
|
+
"@inquirer/type": "^1.2.0"
|
|
60
59
|
},
|
|
61
60
|
"devDependencies": {
|
|
62
|
-
"@inquirer/testing": "^2.1.
|
|
61
|
+
"@inquirer/testing": "^2.1.11"
|
|
63
62
|
},
|
|
64
63
|
"scripts": {
|
|
65
64
|
"tsc": "yarn run tsc:esm && yarn run tsc:cjs",
|
|
@@ -70,7 +69,7 @@
|
|
|
70
69
|
"access": "public"
|
|
71
70
|
},
|
|
72
71
|
"engines": {
|
|
73
|
-
"node": ">=
|
|
72
|
+
"node": ">=18"
|
|
74
73
|
},
|
|
75
74
|
"exports": {
|
|
76
75
|
".": {
|
|
@@ -84,5 +83,5 @@
|
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
},
|
|
87
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "44016a40bc9e93455dfdb9fa6c25c27c1c109bd3"
|
|
88
87
|
}
|