@inquirer/input 4.3.1 → 5.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/input",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Inquirer input text prompt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"answer",
|
|
@@ -53,51 +53,30 @@
|
|
|
53
53
|
"exports": {
|
|
54
54
|
"./package.json": "./package.json",
|
|
55
55
|
".": {
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
"default": "./dist/esm/index.js"
|
|
59
|
-
},
|
|
60
|
-
"require": {
|
|
61
|
-
"types": "./dist/commonjs/index.d.ts",
|
|
62
|
-
"default": "./dist/commonjs/index.js"
|
|
63
|
-
}
|
|
56
|
+
"types": "./dist/index.d.ts",
|
|
57
|
+
"default": "./dist/index.js"
|
|
64
58
|
}
|
|
65
59
|
},
|
|
66
|
-
"main": "./dist/commonjs/index.js",
|
|
67
|
-
"module": "./dist/esm/index.js",
|
|
68
|
-
"types": "./dist/commonjs/index.d.ts",
|
|
69
60
|
"files": [
|
|
70
61
|
"dist"
|
|
71
62
|
],
|
|
72
63
|
"scripts": {
|
|
73
|
-
"
|
|
74
|
-
"tsc": "tshy"
|
|
64
|
+
"tsc": "tsc"
|
|
75
65
|
},
|
|
76
66
|
"dependencies": {
|
|
77
|
-
"@inquirer/core": "^
|
|
78
|
-
"@inquirer/type": "^
|
|
67
|
+
"@inquirer/core": "^11.0.1",
|
|
68
|
+
"@inquirer/type": "^4.0.1"
|
|
79
69
|
},
|
|
80
70
|
"devDependencies": {
|
|
81
|
-
"@
|
|
82
|
-
"
|
|
83
|
-
"@repo/tsconfig": "0.0.0",
|
|
84
|
-
"tshy": "^3.0.3"
|
|
71
|
+
"@inquirer/testing": "^3.0.1",
|
|
72
|
+
"typescript": "^5.9.3"
|
|
85
73
|
},
|
|
86
74
|
"engines": {
|
|
87
|
-
"node": ">=
|
|
75
|
+
"node": ">=23.5.0 || ^22.13.0 || ^21.7.0 || ^20.12.0"
|
|
88
76
|
},
|
|
89
77
|
"publishConfig": {
|
|
90
78
|
"access": "public"
|
|
91
79
|
},
|
|
92
|
-
"tshy": {
|
|
93
|
-
"exclude": [
|
|
94
|
-
"src/**/*.test.ts"
|
|
95
|
-
],
|
|
96
|
-
"exports": {
|
|
97
|
-
"./package.json": "./package.json",
|
|
98
|
-
".": "./src/index.ts"
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
80
|
"peerDependencies": {
|
|
102
81
|
"@types/node": ">=18"
|
|
103
82
|
},
|
|
@@ -106,5 +85,5 @@
|
|
|
106
85
|
"optional": true
|
|
107
86
|
}
|
|
108
87
|
},
|
|
109
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "cce79ce3b9bbdfb4dbb798078cf3b94b9adc7d1b"
|
|
110
89
|
}
|
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/package.json
DELETED
|
File without changes
|
|
File without changes
|