@inquirer/input 0.0.28-alpha.0 → 0.1.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.
|
@@ -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": "0.1.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,34 @@
|
|
|
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.0",
|
|
58
|
+
"@inquirer/type": "^0.1.0",
|
|
59
|
+
"chalk": "^5.2.0"
|
|
58
60
|
},
|
|
59
61
|
"scripts": {
|
|
60
|
-
"tsc": "tsc"
|
|
62
|
+
"tsc": "yarn run clean && yarn run tsc:esm && yarn run tsc:cjs",
|
|
63
|
+
"clean": "rm -rf dist",
|
|
64
|
+
"tsc:esm": "tsc -p ./tsconfig.esm.json",
|
|
65
|
+
"tsc:cjs": "tsc -p ./tsconfig.cjs.json && yarn run fix-ext",
|
|
66
|
+
"fix-ext": "ts-node ../../tools/rename-ext.ts"
|
|
61
67
|
},
|
|
62
68
|
"publishConfig": {
|
|
63
69
|
"access": "public"
|
|
64
70
|
},
|
|
65
|
-
"
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=14.18.0"
|
|
73
|
+
},
|
|
74
|
+
"exports": {
|
|
75
|
+
".": {
|
|
76
|
+
"import": {
|
|
77
|
+
"types": "./dist/esm/types/index.d.mts",
|
|
78
|
+
"default": "./dist/esm/index.mjs"
|
|
79
|
+
},
|
|
80
|
+
"require": {
|
|
81
|
+
"types": "./dist/cjs/types/index.d.mts",
|
|
82
|
+
"default": "./dist/cjs/index.js"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"gitHead": "bd58130dd8204945a31b062070b829003b8385fc"
|
|
66
87
|
}
|
|
File without changes
|