@inquirer/expand 1.1.6 → 1.1.7

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 CHANGED
@@ -10,6 +10,16 @@ const helpChoice = {
10
10
  name: 'Help, list all options',
11
11
  value: undefined,
12
12
  };
13
+ function getChoiceKey(choice, key) {
14
+ if (key === 'name') {
15
+ if ('name' in choice)
16
+ return choice.name;
17
+ return choice.value;
18
+ }
19
+ if ('value' in choice)
20
+ return choice.value;
21
+ return choice.name;
22
+ }
13
23
  exports.default = (0, core_1.createPrompt)((config, done) => {
14
24
  const { choices, default: defaultKey = 'h', expanded: defaultExpandState = false, } = config;
15
25
  const [status, setStatus] = (0, core_1.useState)('pending');
@@ -26,7 +36,7 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
26
36
  else {
27
37
  const selectedChoice = choices.find(({ key }) => key === answer);
28
38
  if (selectedChoice) {
29
- const finalValue = selectedChoice.value || selectedChoice.name;
39
+ const finalValue = getChoiceKey(selectedChoice, 'value');
30
40
  setValue(finalValue);
31
41
  setStatus('done');
32
42
  done(finalValue);
@@ -46,6 +56,7 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
46
56
  });
47
57
  const message = chalk_1.default.bold(config.message);
48
58
  if (status === 'done') {
59
+ // TODO: `value` should be the display name instead of the raw value.
49
60
  return `${prefix} ${message} ${chalk_1.default.cyan(value)}`;
50
61
  }
51
62
  const allChoices = expanded ? choices : [...choices, helpChoice];
@@ -65,7 +76,7 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
65
76
  shortChoices = '';
66
77
  longChoices = allChoices
67
78
  .map((choice) => {
68
- const line = ` ${choice.key}) ${choice.name || choice.value}`;
79
+ const line = ` ${choice.key}) ${getChoiceKey(choice, 'name')}`;
69
80
  if (choice.key === value.toLowerCase()) {
70
81
  return chalk_1.default.cyan(line);
71
82
  }
@@ -76,7 +87,7 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
76
87
  let helpTip = '';
77
88
  const currentOption = allChoices.find(({ key }) => key === value.toLowerCase());
78
89
  if (currentOption) {
79
- helpTip = `${chalk_1.default.cyan('>>')} ${currentOption.name || currentOption.value}`;
90
+ helpTip = `${chalk_1.default.cyan('>>')} ${getChoiceKey(currentOption, 'name')}`;
80
91
  }
81
92
  let error = '';
82
93
  if (errorMsg) {
@@ -1,10 +1,17 @@
1
1
  import { AsyncPromptConfig } from '@inquirer/core';
2
+ type ExpandChoice = {
3
+ key: string;
4
+ name: string;
5
+ } | {
6
+ key: string;
7
+ value: string;
8
+ } | {
9
+ key: string;
10
+ name: string;
11
+ value: string;
12
+ };
2
13
  type ExpandConfig = AsyncPromptConfig & {
3
- choices: {
4
- key: string;
5
- name: string;
6
- value?: string;
7
- }[];
14
+ choices: ReadonlyArray<ExpandChoice>;
8
15
  default?: string;
9
16
  expanded?: boolean;
10
17
  };
@@ -5,6 +5,16 @@ const helpChoice = {
5
5
  name: 'Help, list all options',
6
6
  value: undefined,
7
7
  };
8
+ function getChoiceKey(choice, key) {
9
+ if (key === 'name') {
10
+ if ('name' in choice)
11
+ return choice.name;
12
+ return choice.value;
13
+ }
14
+ if ('value' in choice)
15
+ return choice.value;
16
+ return choice.name;
17
+ }
8
18
  export default createPrompt((config, done) => {
9
19
  const { choices, default: defaultKey = 'h', expanded: defaultExpandState = false, } = config;
10
20
  const [status, setStatus] = useState('pending');
@@ -21,7 +31,7 @@ export default createPrompt((config, done) => {
21
31
  else {
22
32
  const selectedChoice = choices.find(({ key }) => key === answer);
23
33
  if (selectedChoice) {
24
- const finalValue = selectedChoice.value || selectedChoice.name;
34
+ const finalValue = getChoiceKey(selectedChoice, 'value');
25
35
  setValue(finalValue);
26
36
  setStatus('done');
27
37
  done(finalValue);
@@ -41,6 +51,7 @@ export default createPrompt((config, done) => {
41
51
  });
42
52
  const message = chalk.bold(config.message);
43
53
  if (status === 'done') {
54
+ // TODO: `value` should be the display name instead of the raw value.
44
55
  return `${prefix} ${message} ${chalk.cyan(value)}`;
45
56
  }
46
57
  const allChoices = expanded ? choices : [...choices, helpChoice];
@@ -60,7 +71,7 @@ export default createPrompt((config, done) => {
60
71
  shortChoices = '';
61
72
  longChoices = allChoices
62
73
  .map((choice) => {
63
- const line = ` ${choice.key}) ${choice.name || choice.value}`;
74
+ const line = ` ${choice.key}) ${getChoiceKey(choice, 'name')}`;
64
75
  if (choice.key === value.toLowerCase()) {
65
76
  return chalk.cyan(line);
66
77
  }
@@ -71,7 +82,7 @@ export default createPrompt((config, done) => {
71
82
  let helpTip = '';
72
83
  const currentOption = allChoices.find(({ key }) => key === value.toLowerCase());
73
84
  if (currentOption) {
74
- helpTip = `${chalk.cyan('>>')} ${currentOption.name || currentOption.value}`;
85
+ helpTip = `${chalk.cyan('>>')} ${getChoiceKey(currentOption, 'name')}`;
75
86
  }
76
87
  let error = '';
77
88
  if (errorMsg) {
@@ -1,10 +1,17 @@
1
1
  import { AsyncPromptConfig } from '@inquirer/core';
2
+ type ExpandChoice = {
3
+ key: string;
4
+ name: string;
5
+ } | {
6
+ key: string;
7
+ value: string;
8
+ } | {
9
+ key: string;
10
+ name: string;
11
+ value: string;
12
+ };
2
13
  type ExpandConfig = AsyncPromptConfig & {
3
- choices: {
4
- key: string;
5
- name: string;
6
- value?: string;
7
- }[];
14
+ choices: ReadonlyArray<ExpandChoice>;
8
15
  default?: string;
9
16
  expanded?: boolean;
10
17
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/expand",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "Inquirer checkbox prompt",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "typings": "./dist/cjs/types/index.d.ts",
@@ -54,11 +54,14 @@
54
54
  "license": "MIT",
55
55
  "homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/expand/README.md",
56
56
  "dependencies": {
57
- "@inquirer/core": "^3.1.0",
57
+ "@inquirer/core": "^3.1.1",
58
58
  "@inquirer/type": "^1.1.1",
59
59
  "chalk": "^4.1.2",
60
60
  "figures": "^3.2.0"
61
61
  },
62
+ "devDependencies": {
63
+ "@inquirer/testing": "^2.1.2"
64
+ },
62
65
  "scripts": {
63
66
  "tsc": "yarn run clean && yarn run tsc:esm && yarn run tsc:cjs",
64
67
  "clean": "rm -rf dist",
@@ -84,5 +87,5 @@
84
87
  }
85
88
  }
86
89
  },
87
- "gitHead": "ab9dd2f301e02d2cc0fec699ce100b174f2b798e"
90
+ "gitHead": "dd31d57ed3b1d0771e24cc34bc72e5bedb63a1d7"
88
91
  }