@inquirer/input 0.0.28-alpha.0 → 1.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
CHANGED
|
@@ -26,7 +26,7 @@ const answer = await input({ message: 'Enter your name' });
|
|
|
26
26
|
| ----------- | ----------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
27
27
|
| message | `string` | yes | The question to ask |
|
|
28
28
|
| default | `string` | no | Default value if no answer is provided (clear it by pressing backspace) |
|
|
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
|
|
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
31
|
|
|
32
32
|
# License
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const core_1 = require("@inquirer/core");
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
18
|
+
const [status, setStatus] = (0, core_1.useState)('pending');
|
|
19
|
+
const [defaultValue, setDefaultValue] = (0, core_1.useState)(config.default);
|
|
20
|
+
const [errorMsg, setError] = (0, core_1.useState)(undefined);
|
|
21
|
+
const [value, setValue] = (0, core_1.useState)('');
|
|
22
|
+
const isLoading = status === 'loading';
|
|
23
|
+
const prefix = (0, core_1.usePrefix)(isLoading);
|
|
24
|
+
(0, core_1.useKeypress)((key, rl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
// Ignore keypress while our prompt is doing other processing.
|
|
26
|
+
if (status !== 'pending') {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if ((0, core_1.isEnterKey)(key)) {
|
|
30
|
+
const answer = value || defaultValue || '';
|
|
31
|
+
setStatus('loading');
|
|
32
|
+
const isValid = yield config.validate(answer);
|
|
33
|
+
if (isValid === true) {
|
|
34
|
+
setValue(answer);
|
|
35
|
+
setStatus('done');
|
|
36
|
+
done(answer);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// TODO: Can we keep the value after validation failure?
|
|
40
|
+
// `rl.line = value` works but it looses the cursor position.
|
|
41
|
+
setValue('');
|
|
42
|
+
setError(isValid || 'You must provide a valid value');
|
|
43
|
+
setStatus('pending');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if ((0, core_1.isBackspaceKey)(key) && !value) {
|
|
47
|
+
setDefaultValue(undefined);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
setValue(rl.line);
|
|
51
|
+
setError(undefined);
|
|
52
|
+
}
|
|
53
|
+
}));
|
|
54
|
+
const message = chalk_1.default.bold(config.message);
|
|
55
|
+
let formattedValue = value;
|
|
56
|
+
if (typeof config.transformer === 'function') {
|
|
57
|
+
formattedValue = config.transformer(value, { isFinal: status === 'done' });
|
|
58
|
+
}
|
|
59
|
+
if (status === 'done') {
|
|
60
|
+
formattedValue = chalk_1.default.cyan(formattedValue);
|
|
61
|
+
}
|
|
62
|
+
let defaultStr = '';
|
|
63
|
+
if (defaultValue && status !== 'done' && !value) {
|
|
64
|
+
defaultStr = chalk_1.default.dim(` (${defaultValue})`);
|
|
65
|
+
}
|
|
66
|
+
let error = '';
|
|
67
|
+
if (errorMsg) {
|
|
68
|
+
error = chalk_1.default.red(`> ${errorMsg}`);
|
|
69
|
+
}
|
|
70
|
+
return [`${prefix} ${message}${defaultStr} ${formattedValue}`, error];
|
|
71
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AsyncPromptConfig } from '@inquirer/core';
|
|
2
|
+
type InputConfig = AsyncPromptConfig & {
|
|
3
|
+
default?: string;
|
|
4
|
+
transformer?: (value: string, { isFinal }: {
|
|
5
|
+
isFinal: boolean;
|
|
6
|
+
}) => string;
|
|
7
|
+
};
|
|
8
|
+
declare const _default: import("@inquirer/type").Prompt<string, InputConfig>;
|
|
9
|
+
export default _default;
|
package/package.json
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/input",
|
|
3
|
-
"
|
|
4
|
-
"version": "0.0.28-alpha.0",
|
|
3
|
+
"version": "1.0.0",
|
|
5
4
|
"description": "Inquirer input text prompt",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"typings": "dist/index.d.
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"typings": "./dist/cjs/types/index.d.mts",
|
|
8
7
|
"files": [
|
|
9
|
-
"dist
|
|
8
|
+
"dist/**/*"
|
|
10
9
|
],
|
|
11
|
-
"repository":
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/SBoudrias/Inquirer.js.git"
|
|
13
|
+
},
|
|
12
14
|
"keywords": [
|
|
13
15
|
"answer",
|
|
14
16
|
"answers",
|
|
15
17
|
"ask",
|
|
16
18
|
"base",
|
|
17
19
|
"cli",
|
|
18
|
-
"cli",
|
|
19
20
|
"command",
|
|
20
21
|
"command-line",
|
|
21
22
|
"confirm",
|
|
@@ -53,14 +54,38 @@
|
|
|
53
54
|
"license": "MIT",
|
|
54
55
|
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/input/README.md",
|
|
55
56
|
"dependencies": {
|
|
56
|
-
"@inquirer/core": "^
|
|
57
|
-
"
|
|
57
|
+
"@inquirer/core": "^1.0.1",
|
|
58
|
+
"@inquirer/type": "^1.0.0",
|
|
59
|
+
"chalk": "^5.2.0"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@inquirer/testing": "^1.0.0",
|
|
63
|
+
"@jest/globals": "^29.5.0"
|
|
58
64
|
},
|
|
59
65
|
"scripts": {
|
|
60
|
-
"tsc": "tsc"
|
|
66
|
+
"tsc": "yarn run clean && yarn run tsc:esm && yarn run tsc:cjs",
|
|
67
|
+
"clean": "rm -rf dist",
|
|
68
|
+
"tsc:esm": "tsc -p ./tsconfig.esm.json",
|
|
69
|
+
"tsc:cjs": "tsc -p ./tsconfig.cjs.json && yarn run fix-ext",
|
|
70
|
+
"fix-ext": "ts-node ../../tools/rename-ext.ts"
|
|
61
71
|
},
|
|
62
72
|
"publishConfig": {
|
|
63
73
|
"access": "public"
|
|
64
74
|
},
|
|
65
|
-
"
|
|
75
|
+
"engines": {
|
|
76
|
+
"node": ">=14.18.0"
|
|
77
|
+
},
|
|
78
|
+
"exports": {
|
|
79
|
+
".": {
|
|
80
|
+
"import": {
|
|
81
|
+
"types": "./dist/esm/types/index.d.mts",
|
|
82
|
+
"default": "./dist/esm/index.mjs"
|
|
83
|
+
},
|
|
84
|
+
"require": {
|
|
85
|
+
"types": "./dist/cjs/types/index.d.mts",
|
|
86
|
+
"default": "./dist/cjs/index.js"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"gitHead": "e93c4cb14f0c35ebd1efb065776b90f48899b075"
|
|
66
91
|
}
|
|
File without changes
|