@inquirer/rawlist 1.0.6 → 1.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.
- package/dist/cjs/index.js +18 -10
- package/dist/cjs/types/index.d.mts +10 -8
- package/dist/esm/index.mjs +18 -11
- package/dist/esm/types/index.d.mts +10 -8
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -3,9 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Separator = void 0;
|
|
6
7
|
const core_1 = require("@inquirer/core");
|
|
8
|
+
Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return core_1.Separator; } });
|
|
7
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
10
|
const numberRegex = /[0-9]+/;
|
|
11
|
+
function isSelectableChoice(choice) {
|
|
12
|
+
return choice != null && !core_1.Separator.isSeparator(choice);
|
|
13
|
+
}
|
|
9
14
|
exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
10
15
|
const { choices } = config;
|
|
11
16
|
const [status, setStatus] = (0, core_1.useState)('pending');
|
|
@@ -17,17 +22,16 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
17
22
|
let selectedChoice;
|
|
18
23
|
if (numberRegex.test(value)) {
|
|
19
24
|
const answer = parseInt(value, 10) - 1;
|
|
20
|
-
selectedChoice = choices[answer];
|
|
25
|
+
selectedChoice = choices.filter(isSelectableChoice)[answer];
|
|
21
26
|
}
|
|
22
27
|
else {
|
|
23
28
|
const answer = value.toLowerCase();
|
|
24
|
-
selectedChoice = choices.find((
|
|
29
|
+
selectedChoice = choices.find((choice) => isSelectableChoice(choice) && choice.key === answer);
|
|
25
30
|
}
|
|
26
|
-
if (selectedChoice) {
|
|
27
|
-
|
|
28
|
-
setValue(finalValue);
|
|
31
|
+
if (isSelectableChoice(selectedChoice)) {
|
|
32
|
+
setValue(selectedChoice.name || String(selectedChoice.value));
|
|
29
33
|
setStatus('done');
|
|
30
|
-
done(
|
|
34
|
+
done(selectedChoice.value);
|
|
31
35
|
}
|
|
32
36
|
else if (value === '') {
|
|
33
37
|
setError('Please input a value');
|
|
@@ -45,11 +49,15 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
|
|
|
45
49
|
if (status === 'done') {
|
|
46
50
|
return `${prefix} ${message} ${chalk_1.default.cyan(value)}`;
|
|
47
51
|
}
|
|
52
|
+
let index = 0;
|
|
48
53
|
const choicesStr = choices
|
|
49
|
-
.map((choice
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
.map((choice) => {
|
|
55
|
+
if (core_1.Separator.isSeparator(choice)) {
|
|
56
|
+
return ` ${choice.separator}`;
|
|
57
|
+
}
|
|
58
|
+
index += 1;
|
|
59
|
+
const line = ` ${choice.key || index}) ${choice.name || choice.value}`;
|
|
60
|
+
if (choice.key === value.toLowerCase() || String(index) === value) {
|
|
53
61
|
return chalk_1.default.cyan(line);
|
|
54
62
|
}
|
|
55
63
|
return line;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { AsyncPromptConfig } from '@inquirer/core';
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}[];
|
|
1
|
+
import { AsyncPromptConfig, Separator } from '@inquirer/core';
|
|
2
|
+
type Choice<Value> = {
|
|
3
|
+
value: Value;
|
|
4
|
+
name?: string;
|
|
5
|
+
key?: string;
|
|
6
|
+
type?: never;
|
|
8
7
|
};
|
|
9
|
-
declare const _default:
|
|
8
|
+
declare const _default: <Value extends unknown>(config: AsyncPromptConfig & {
|
|
9
|
+
choices: readonly (Separator | Choice<Value>)[];
|
|
10
|
+
}, context?: import("@inquirer/type").Context | undefined) => Promise<Value>;
|
|
10
11
|
export default _default;
|
|
12
|
+
export { Separator };
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, } from '@inquirer/core';
|
|
1
|
+
import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, Separator, } from '@inquirer/core';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
const numberRegex = /[0-9]+/;
|
|
4
|
+
function isSelectableChoice(choice) {
|
|
5
|
+
return choice != null && !Separator.isSeparator(choice);
|
|
6
|
+
}
|
|
4
7
|
export default createPrompt((config, done) => {
|
|
5
8
|
const { choices } = config;
|
|
6
9
|
const [status, setStatus] = useState('pending');
|
|
@@ -12,17 +15,16 @@ export default createPrompt((config, done) => {
|
|
|
12
15
|
let selectedChoice;
|
|
13
16
|
if (numberRegex.test(value)) {
|
|
14
17
|
const answer = parseInt(value, 10) - 1;
|
|
15
|
-
selectedChoice = choices[answer];
|
|
18
|
+
selectedChoice = choices.filter(isSelectableChoice)[answer];
|
|
16
19
|
}
|
|
17
20
|
else {
|
|
18
21
|
const answer = value.toLowerCase();
|
|
19
|
-
selectedChoice = choices.find((
|
|
22
|
+
selectedChoice = choices.find((choice) => isSelectableChoice(choice) && choice.key === answer);
|
|
20
23
|
}
|
|
21
|
-
if (selectedChoice) {
|
|
22
|
-
|
|
23
|
-
setValue(finalValue);
|
|
24
|
+
if (isSelectableChoice(selectedChoice)) {
|
|
25
|
+
setValue(selectedChoice.name || String(selectedChoice.value));
|
|
24
26
|
setStatus('done');
|
|
25
|
-
done(
|
|
27
|
+
done(selectedChoice.value);
|
|
26
28
|
}
|
|
27
29
|
else if (value === '') {
|
|
28
30
|
setError('Please input a value');
|
|
@@ -40,11 +42,15 @@ export default createPrompt((config, done) => {
|
|
|
40
42
|
if (status === 'done') {
|
|
41
43
|
return `${prefix} ${message} ${chalk.cyan(value)}`;
|
|
42
44
|
}
|
|
45
|
+
let index = 0;
|
|
43
46
|
const choicesStr = choices
|
|
44
|
-
.map((choice
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
.map((choice) => {
|
|
48
|
+
if (Separator.isSeparator(choice)) {
|
|
49
|
+
return ` ${choice.separator}`;
|
|
50
|
+
}
|
|
51
|
+
index += 1;
|
|
52
|
+
const line = ` ${choice.key || index}) ${choice.name || choice.value}`;
|
|
53
|
+
if (choice.key === value.toLowerCase() || String(index) === value) {
|
|
48
54
|
return chalk.cyan(line);
|
|
49
55
|
}
|
|
50
56
|
return line;
|
|
@@ -59,3 +65,4 @@ export default createPrompt((config, done) => {
|
|
|
59
65
|
[choicesStr, error].filter(Boolean).join('\n'),
|
|
60
66
|
];
|
|
61
67
|
});
|
|
68
|
+
export { Separator };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { AsyncPromptConfig } from '@inquirer/core';
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}[];
|
|
1
|
+
import { AsyncPromptConfig, Separator } from '@inquirer/core';
|
|
2
|
+
type Choice<Value> = {
|
|
3
|
+
value: Value;
|
|
4
|
+
name?: string;
|
|
5
|
+
key?: string;
|
|
6
|
+
type?: never;
|
|
8
7
|
};
|
|
9
|
-
declare const _default:
|
|
8
|
+
declare const _default: <Value extends unknown>(config: AsyncPromptConfig & {
|
|
9
|
+
choices: readonly (Separator | Choice<Value>)[];
|
|
10
|
+
}, context?: import("@inquirer/type").Context | undefined) => Promise<Value>;
|
|
10
11
|
export default _default;
|
|
12
|
+
export { Separator };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/rawlist",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Inquirer rawlist prompt",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"typings": "./dist/cjs/types/index.d.mts",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"license": "MIT",
|
|
55
55
|
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/rawlist/README.md",
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@inquirer/core": "^1.
|
|
57
|
+
"@inquirer/core": "^1.2.0",
|
|
58
58
|
"@inquirer/type": "^1.0.3",
|
|
59
59
|
"chalk": "^4.1.2"
|
|
60
60
|
},
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "f3a176d916fe26038c9fb57f1ab485aa79c053ce"
|
|
87
87
|
}
|