@inquirer/input 5.0.0 → 5.0.2
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/package.json +12 -15
- package/dist/commonjs/index.d.ts +0 -20
- package/dist/commonjs/index.js +0 -99
- package/dist/commonjs/package.json +0 -3
- package/dist/esm/index.d.ts +0 -20
- package/dist/esm/index.js +0 -97
- package/dist/esm/package.json +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/input",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "Inquirer input text prompt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"answer",
|
|
@@ -52,7 +52,10 @@
|
|
|
52
52
|
"type": "module",
|
|
53
53
|
"exports": {
|
|
54
54
|
"./package.json": "./package.json",
|
|
55
|
-
".":
|
|
55
|
+
".": {
|
|
56
|
+
"types": "./dist/index.d.ts",
|
|
57
|
+
"default": "./dist/index.js"
|
|
58
|
+
}
|
|
56
59
|
},
|
|
57
60
|
"files": [
|
|
58
61
|
"dist"
|
|
@@ -61,26 +64,18 @@
|
|
|
61
64
|
"tsc": "tsc"
|
|
62
65
|
},
|
|
63
66
|
"dependencies": {
|
|
64
|
-
"@inquirer/core": "^11.0.
|
|
65
|
-
"@inquirer/type": "^4.0.
|
|
67
|
+
"@inquirer/core": "^11.0.2",
|
|
68
|
+
"@inquirer/type": "^4.0.2"
|
|
66
69
|
},
|
|
67
70
|
"devDependencies": {
|
|
68
|
-
"@inquirer/testing": "^3.0.
|
|
69
|
-
"@repo/tsconfig": "0.0.0",
|
|
71
|
+
"@inquirer/testing": "^3.0.2",
|
|
70
72
|
"typescript": "^5.9.3"
|
|
71
73
|
},
|
|
72
74
|
"engines": {
|
|
73
75
|
"node": ">=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0"
|
|
74
76
|
},
|
|
75
77
|
"publishConfig": {
|
|
76
|
-
"access": "public"
|
|
77
|
-
"exports": {
|
|
78
|
-
"./package.json": "./package.json",
|
|
79
|
-
".": {
|
|
80
|
-
"types": "./dist/index.d.ts",
|
|
81
|
-
"default": "./dist/index.js"
|
|
82
|
-
}
|
|
83
|
-
}
|
|
78
|
+
"access": "public"
|
|
84
79
|
},
|
|
85
80
|
"peerDependencies": {
|
|
86
81
|
"@types/node": ">=18"
|
|
@@ -90,5 +85,7 @@
|
|
|
90
85
|
"optional": true
|
|
91
86
|
}
|
|
92
87
|
},
|
|
93
|
-
"
|
|
88
|
+
"main": "./dist/index.js",
|
|
89
|
+
"types": "./dist/index.d.ts",
|
|
90
|
+
"gitHead": "9c724296daad3d740b09173f9aae035dc62cb106"
|
|
94
91
|
}
|
package/dist/commonjs/index.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type Theme } from '@inquirer/core';
|
|
2
|
-
import type { PartialDeep } from '@inquirer/type';
|
|
3
|
-
type InputTheme = {
|
|
4
|
-
validationFailureMode: 'keep' | 'clear';
|
|
5
|
-
};
|
|
6
|
-
type InputConfig = {
|
|
7
|
-
message: string;
|
|
8
|
-
default?: string;
|
|
9
|
-
prefill?: 'tab' | 'editable';
|
|
10
|
-
required?: boolean;
|
|
11
|
-
transformer?: (value: string, { isFinal }: {
|
|
12
|
-
isFinal: boolean;
|
|
13
|
-
}) => string;
|
|
14
|
-
validate?: (value: string) => boolean | string | Promise<string | boolean>;
|
|
15
|
-
theme?: PartialDeep<Theme<InputTheme>>;
|
|
16
|
-
pattern?: RegExp;
|
|
17
|
-
patternError?: string;
|
|
18
|
-
};
|
|
19
|
-
declare const _default: import("@inquirer/type").Prompt<string, InputConfig>;
|
|
20
|
-
export default _default;
|
package/dist/commonjs/index.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const core_1 = require("@inquirer/core");
|
|
4
|
-
const inputTheme = {
|
|
5
|
-
validationFailureMode: 'keep',
|
|
6
|
-
};
|
|
7
|
-
exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
8
|
-
const { prefill = 'tab' } = config;
|
|
9
|
-
const theme = (0, core_1.makeTheme)(inputTheme, config.theme);
|
|
10
|
-
const [status, setStatus] = (0, core_1.useState)('idle');
|
|
11
|
-
const [defaultValue = '', setDefaultValue] = (0, core_1.useState)(config.default);
|
|
12
|
-
const [errorMsg, setError] = (0, core_1.useState)();
|
|
13
|
-
const [value, setValue] = (0, core_1.useState)('');
|
|
14
|
-
const prefix = (0, core_1.usePrefix)({ status, theme });
|
|
15
|
-
async function validate(value) {
|
|
16
|
-
const { required, pattern, patternError = 'Invalid input' } = config;
|
|
17
|
-
if (required && !value) {
|
|
18
|
-
return 'You must provide a value';
|
|
19
|
-
}
|
|
20
|
-
if (pattern && !pattern.test(value)) {
|
|
21
|
-
return patternError;
|
|
22
|
-
}
|
|
23
|
-
if (typeof config.validate === 'function') {
|
|
24
|
-
return (await config.validate(value)) || 'You must provide a valid value';
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
(0, core_1.useKeypress)(async (key, rl) => {
|
|
29
|
-
// Ignore keypress while our prompt is doing other processing.
|
|
30
|
-
if (status !== 'idle') {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if ((0, core_1.isEnterKey)(key)) {
|
|
34
|
-
const answer = value || defaultValue;
|
|
35
|
-
setStatus('loading');
|
|
36
|
-
const isValid = await validate(answer);
|
|
37
|
-
if (isValid === true) {
|
|
38
|
-
setValue(answer);
|
|
39
|
-
setStatus('done');
|
|
40
|
-
done(answer);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
if (theme.validationFailureMode === 'clear') {
|
|
44
|
-
setValue('');
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
// Reset the readline line value to the previous value. On line event, the value
|
|
48
|
-
// get cleared, forcing the user to re-enter the value instead of fixing it.
|
|
49
|
-
rl.write(value);
|
|
50
|
-
}
|
|
51
|
-
setError(isValid);
|
|
52
|
-
setStatus('idle');
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
else if ((0, core_1.isBackspaceKey)(key) && !value) {
|
|
56
|
-
setDefaultValue(undefined);
|
|
57
|
-
}
|
|
58
|
-
else if ((0, core_1.isTabKey)(key) && !value) {
|
|
59
|
-
setDefaultValue(undefined);
|
|
60
|
-
rl.clearLine(0); // Remove the tab character.
|
|
61
|
-
rl.write(defaultValue);
|
|
62
|
-
setValue(defaultValue);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
setValue(rl.line);
|
|
66
|
-
setError(undefined);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
// If prefill is set to 'editable' cut out the default value and paste into current state and the user's cli buffer
|
|
70
|
-
// They can edit the value immediately instead of needing to press 'tab'
|
|
71
|
-
(0, core_1.useEffect)((rl) => {
|
|
72
|
-
if (prefill === 'editable' && defaultValue) {
|
|
73
|
-
rl.write(defaultValue);
|
|
74
|
-
setValue(defaultValue);
|
|
75
|
-
}
|
|
76
|
-
}, []);
|
|
77
|
-
const message = theme.style.message(config.message, status);
|
|
78
|
-
let formattedValue = value;
|
|
79
|
-
if (typeof config.transformer === 'function') {
|
|
80
|
-
formattedValue = config.transformer(value, { isFinal: status === 'done' });
|
|
81
|
-
}
|
|
82
|
-
else if (status === 'done') {
|
|
83
|
-
formattedValue = theme.style.answer(value);
|
|
84
|
-
}
|
|
85
|
-
let defaultStr;
|
|
86
|
-
if (defaultValue && status !== 'done' && !value) {
|
|
87
|
-
defaultStr = theme.style.defaultAnswer(defaultValue);
|
|
88
|
-
}
|
|
89
|
-
let error = '';
|
|
90
|
-
if (errorMsg) {
|
|
91
|
-
error = theme.style.error(errorMsg);
|
|
92
|
-
}
|
|
93
|
-
return [
|
|
94
|
-
[prefix, message, defaultStr, formattedValue]
|
|
95
|
-
.filter((v) => v !== undefined)
|
|
96
|
-
.join(' '),
|
|
97
|
-
error,
|
|
98
|
-
];
|
|
99
|
-
});
|
package/dist/esm/index.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type Theme } from '@inquirer/core';
|
|
2
|
-
import type { PartialDeep } from '@inquirer/type';
|
|
3
|
-
type InputTheme = {
|
|
4
|
-
validationFailureMode: 'keep' | 'clear';
|
|
5
|
-
};
|
|
6
|
-
type InputConfig = {
|
|
7
|
-
message: string;
|
|
8
|
-
default?: string;
|
|
9
|
-
prefill?: 'tab' | 'editable';
|
|
10
|
-
required?: boolean;
|
|
11
|
-
transformer?: (value: string, { isFinal }: {
|
|
12
|
-
isFinal: boolean;
|
|
13
|
-
}) => string;
|
|
14
|
-
validate?: (value: string) => boolean | string | Promise<string | boolean>;
|
|
15
|
-
theme?: PartialDeep<Theme<InputTheme>>;
|
|
16
|
-
pattern?: RegExp;
|
|
17
|
-
patternError?: string;
|
|
18
|
-
};
|
|
19
|
-
declare const _default: import("@inquirer/type").Prompt<string, InputConfig>;
|
|
20
|
-
export default _default;
|
package/dist/esm/index.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { createPrompt, useState, useKeypress, useEffect, usePrefix, isBackspaceKey, isEnterKey, isTabKey, makeTheme, } from '@inquirer/core';
|
|
2
|
-
const inputTheme = {
|
|
3
|
-
validationFailureMode: 'keep',
|
|
4
|
-
};
|
|
5
|
-
export default createPrompt((config, done) => {
|
|
6
|
-
const { prefill = 'tab' } = config;
|
|
7
|
-
const theme = makeTheme(inputTheme, config.theme);
|
|
8
|
-
const [status, setStatus] = useState('idle');
|
|
9
|
-
const [defaultValue = '', setDefaultValue] = useState(config.default);
|
|
10
|
-
const [errorMsg, setError] = useState();
|
|
11
|
-
const [value, setValue] = useState('');
|
|
12
|
-
const prefix = usePrefix({ status, theme });
|
|
13
|
-
async function validate(value) {
|
|
14
|
-
const { required, pattern, patternError = 'Invalid input' } = config;
|
|
15
|
-
if (required && !value) {
|
|
16
|
-
return 'You must provide a value';
|
|
17
|
-
}
|
|
18
|
-
if (pattern && !pattern.test(value)) {
|
|
19
|
-
return patternError;
|
|
20
|
-
}
|
|
21
|
-
if (typeof config.validate === 'function') {
|
|
22
|
-
return (await config.validate(value)) || 'You must provide a valid value';
|
|
23
|
-
}
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
useKeypress(async (key, rl) => {
|
|
27
|
-
// Ignore keypress while our prompt is doing other processing.
|
|
28
|
-
if (status !== 'idle') {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (isEnterKey(key)) {
|
|
32
|
-
const answer = value || defaultValue;
|
|
33
|
-
setStatus('loading');
|
|
34
|
-
const isValid = await validate(answer);
|
|
35
|
-
if (isValid === true) {
|
|
36
|
-
setValue(answer);
|
|
37
|
-
setStatus('done');
|
|
38
|
-
done(answer);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
if (theme.validationFailureMode === 'clear') {
|
|
42
|
-
setValue('');
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
// Reset the readline line value to the previous value. On line event, the value
|
|
46
|
-
// get cleared, forcing the user to re-enter the value instead of fixing it.
|
|
47
|
-
rl.write(value);
|
|
48
|
-
}
|
|
49
|
-
setError(isValid);
|
|
50
|
-
setStatus('idle');
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else if (isBackspaceKey(key) && !value) {
|
|
54
|
-
setDefaultValue(undefined);
|
|
55
|
-
}
|
|
56
|
-
else if (isTabKey(key) && !value) {
|
|
57
|
-
setDefaultValue(undefined);
|
|
58
|
-
rl.clearLine(0); // Remove the tab character.
|
|
59
|
-
rl.write(defaultValue);
|
|
60
|
-
setValue(defaultValue);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
setValue(rl.line);
|
|
64
|
-
setError(undefined);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
// If prefill is set to 'editable' cut out the default value and paste into current state and the user's cli buffer
|
|
68
|
-
// They can edit the value immediately instead of needing to press 'tab'
|
|
69
|
-
useEffect((rl) => {
|
|
70
|
-
if (prefill === 'editable' && defaultValue) {
|
|
71
|
-
rl.write(defaultValue);
|
|
72
|
-
setValue(defaultValue);
|
|
73
|
-
}
|
|
74
|
-
}, []);
|
|
75
|
-
const message = theme.style.message(config.message, status);
|
|
76
|
-
let formattedValue = value;
|
|
77
|
-
if (typeof config.transformer === 'function') {
|
|
78
|
-
formattedValue = config.transformer(value, { isFinal: status === 'done' });
|
|
79
|
-
}
|
|
80
|
-
else if (status === 'done') {
|
|
81
|
-
formattedValue = theme.style.answer(value);
|
|
82
|
-
}
|
|
83
|
-
let defaultStr;
|
|
84
|
-
if (defaultValue && status !== 'done' && !value) {
|
|
85
|
-
defaultStr = theme.style.defaultAnswer(defaultValue);
|
|
86
|
-
}
|
|
87
|
-
let error = '';
|
|
88
|
-
if (errorMsg) {
|
|
89
|
-
error = theme.style.error(errorMsg);
|
|
90
|
-
}
|
|
91
|
-
return [
|
|
92
|
-
[prefix, message, defaultStr, formattedValue]
|
|
93
|
-
.filter((v) => v !== undefined)
|
|
94
|
-
.join(' '),
|
|
95
|
-
error,
|
|
96
|
-
];
|
|
97
|
-
});
|
package/dist/esm/package.json
DELETED