@inquirer/rawlist 2.1.18 → 2.2.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/README.md CHANGED
@@ -67,11 +67,33 @@ const answer = await rawlist({
67
67
 
68
68
  ## Options
69
69
 
70
- | Property | Type | Required | Description |
71
- | -------- | ------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
72
- | message | `string` | yes | The question to ask |
73
- | choices | `Array<{ value: string, name?: string, key?: string }>` | yes | List of the available choices. The `value` will be returned as the answer, and used as display if no `name` is defined. By default, choices will be selected by index. This can be customized by using the `key` option. |
74
- | theme | [See Theming](#Theming) | no | Customize look of the prompt. |
70
+ | Property | Type | Required | Description |
71
+ | -------- | ----------------------- | -------- | ------------------------------ |
72
+ | message | `string` | yes | The question to ask |
73
+ | choices | `Choice[]` | yes | List of the available choices. |
74
+ | theme | [See Theming](#Theming) | no | Customize look of the prompt. |
75
+
76
+ `Separator` objects can be used in the `choices` array to render non-selectable lines in the choice list. By default it'll render a line, but you can provide the text as argument (`new Separator('-- Dependencies --')`). This option is often used to add labels to groups within long list of options.
77
+
78
+ ### `Choice` object
79
+
80
+ The `Choice` object is typed as
81
+
82
+ ```ts
83
+ type Choice<Value> = {
84
+ value: Value;
85
+ name?: string;
86
+ short?: string;
87
+ key?: string;
88
+ };
89
+ ```
90
+
91
+ Here's each property:
92
+
93
+ - `value`: The value is what will be returned by `await select()`.
94
+ - `name`: This is the string displayed in the choice list.
95
+ - `short`: Once the prompt is done (press enter), we'll use `short` if defined to render next to the question. By default we'll use `name`.
96
+ - `key`: The key of the choice. Displayed as `key) name`.
75
97
 
76
98
  ## Theming
77
99
 
package/dist/cjs/index.js CHANGED
@@ -18,6 +18,7 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
18
18
  const theme = (0, core_1.makeTheme)(config.theme);
19
19
  const prefix = (0, core_1.usePrefix)({ theme });
20
20
  (0, core_1.useKeypress)((key, rl) => {
21
+ var _a, _b;
21
22
  if ((0, core_1.isEnterKey)(key)) {
22
23
  let selectedChoice;
23
24
  if (numberRegex.test(value)) {
@@ -25,11 +26,10 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
25
26
  selectedChoice = choices.filter(isSelectableChoice)[answer];
26
27
  }
27
28
  else {
28
- const answer = value.toLowerCase();
29
- selectedChoice = choices.find((choice) => isSelectableChoice(choice) && choice.key === answer);
29
+ selectedChoice = choices.find((choice) => isSelectableChoice(choice) && choice.key === value);
30
30
  }
31
31
  if (isSelectableChoice(selectedChoice)) {
32
- setValue(selectedChoice.name || String(selectedChoice.value));
32
+ setValue((_b = (_a = selectedChoice.short) !== null && _a !== void 0 ? _a : selectedChoice.name) !== null && _b !== void 0 ? _b : String(selectedChoice.value));
33
33
  setStatus('done');
34
34
  done(selectedChoice.value);
35
35
  }
@@ -3,6 +3,7 @@ import type { PartialDeep } from '@inquirer/type';
3
3
  type Choice<Value> = {
4
4
  value: Value;
5
5
  name?: string;
6
+ short?: string;
6
7
  key?: string;
7
8
  };
8
9
  declare const _default: <Value>(config: {
@@ -19,11 +19,10 @@ export default createPrompt((config, done) => {
19
19
  selectedChoice = choices.filter(isSelectableChoice)[answer];
20
20
  }
21
21
  else {
22
- const answer = value.toLowerCase();
23
- selectedChoice = choices.find((choice) => isSelectableChoice(choice) && choice.key === answer);
22
+ selectedChoice = choices.find((choice) => isSelectableChoice(choice) && choice.key === value);
24
23
  }
25
24
  if (isSelectableChoice(selectedChoice)) {
26
- setValue(selectedChoice.name || String(selectedChoice.value));
25
+ setValue(selectedChoice.short ?? selectedChoice.name ?? String(selectedChoice.value));
27
26
  setStatus('done');
28
27
  done(selectedChoice.value);
29
28
  }
@@ -3,6 +3,7 @@ import type { PartialDeep } from '@inquirer/type';
3
3
  type Choice<Value> = {
4
4
  value: Value;
5
5
  name?: string;
6
+ short?: string;
6
7
  key?: string;
7
8
  };
8
9
  declare const _default: <Value>(config: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/rawlist",
3
- "version": "2.1.18",
3
+ "version": "2.2.1",
4
4
  "description": "Inquirer rawlist prompt",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "typings": "./dist/cjs/types/index.d.ts",
@@ -54,12 +54,12 @@
54
54
  "license": "MIT",
55
55
  "homepage": "https://github.com/SBoudrias/Inquirer.js/blob/main/packages/rawlist/README.md",
56
56
  "dependencies": {
57
- "@inquirer/core": "^9.0.6",
57
+ "@inquirer/core": "^9.0.7",
58
58
  "@inquirer/type": "^1.5.1",
59
59
  "yoctocolors-cjs": "^2.1.2"
60
60
  },
61
61
  "devDependencies": {
62
- "@inquirer/testing": "^2.1.29"
62
+ "@inquirer/testing": "^2.1.30"
63
63
  },
64
64
  "scripts": {
65
65
  "tsc": "yarn run tsc:esm && yarn run tsc:cjs",
@@ -86,5 +86,5 @@
86
86
  }
87
87
  },
88
88
  "sideEffects": false,
89
- "gitHead": "7a061f13e053dd64ef7373b08e8a10130131ea59"
89
+ "gitHead": "b89972b992a65005afd6397b57aa4635010a5ef7"
90
90
  }