@inquirer/rawlist
Advanced tools
Comparing version 1.0.7 to 1.1.0
@@ -6,5 +6,10 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Separator = void 0; | ||
const core_1 = require("@inquirer/core"); | ||
Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return core_1.Separator; } }); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const numberRegex = /[0-9]+/; | ||
function isSelectableChoice(choice) { | ||
return choice != null && !core_1.Separator.isSeparator(choice); | ||
} | ||
exports.default = (0, core_1.createPrompt)((config, done) => { | ||
@@ -21,13 +26,12 @@ const { choices } = config; | ||
const answer = parseInt(value, 10) - 1; | ||
selectedChoice = choices[answer]; | ||
selectedChoice = choices.filter(isSelectableChoice)[answer]; | ||
} | ||
else { | ||
const answer = value.toLowerCase(); | ||
selectedChoice = choices.find(({ key }) => key === answer); | ||
selectedChoice = choices.find((choice) => isSelectableChoice(choice) && choice.key === answer); | ||
} | ||
if (selectedChoice) { | ||
const finalValue = selectedChoice.value || selectedChoice.name; | ||
setValue(finalValue); | ||
if (isSelectableChoice(selectedChoice)) { | ||
setValue(selectedChoice.name || String(selectedChoice.value)); | ||
setStatus('done'); | ||
done(finalValue); | ||
done(selectedChoice.value); | ||
} | ||
@@ -50,7 +54,11 @@ else if (value === '') { | ||
} | ||
let index = 0; | ||
const choicesStr = choices | ||
.map((choice, index) => { | ||
const humanIndex = index + 1; | ||
const line = ` ${choice.key || humanIndex}) ${choice.name || choice.value}`; | ||
if (choice.key === value.toLowerCase() || String(humanIndex) === value) { | ||
.map((choice) => { | ||
if (core_1.Separator.isSeparator(choice)) { | ||
return ` ${choice.separator}`; | ||
} | ||
index += 1; | ||
const line = ` ${choice.key || index}) ${choice.name || choice.value}`; | ||
if (choice.key === value.toLowerCase() || String(index) === value) { | ||
return chalk_1.default.cyan(line); | ||
@@ -57,0 +65,0 @@ } |
@@ -6,5 +6,10 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Separator = void 0; | ||
const core_1 = require("@inquirer/core"); | ||
Object.defineProperty(exports, "Separator", { enumerable: true, get: function () { return core_1.Separator; } }); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const numberRegex = /[0-9]+/; | ||
function isSelectableChoice(choice) { | ||
return choice != null && !core_1.Separator.isSeparator(choice); | ||
} | ||
exports.default = (0, core_1.createPrompt)((config, done) => { | ||
@@ -21,13 +26,12 @@ const { choices } = config; | ||
const answer = parseInt(value, 10) - 1; | ||
selectedChoice = choices[answer]; | ||
selectedChoice = choices.filter(isSelectableChoice)[answer]; | ||
} | ||
else { | ||
const answer = value.toLowerCase(); | ||
selectedChoice = choices.find(({ key }) => key === answer); | ||
selectedChoice = choices.find((choice) => isSelectableChoice(choice) && choice.key === answer); | ||
} | ||
if (selectedChoice) { | ||
const finalValue = selectedChoice.value || selectedChoice.name; | ||
setValue(finalValue); | ||
if (isSelectableChoice(selectedChoice)) { | ||
setValue(selectedChoice.name || String(selectedChoice.value)); | ||
setStatus('done'); | ||
done(finalValue); | ||
done(selectedChoice.value); | ||
} | ||
@@ -50,7 +54,11 @@ else if (value === '') { | ||
} | ||
let index = 0; | ||
const choicesStr = choices | ||
.map((choice, index) => { | ||
const humanIndex = index + 1; | ||
const line = ` ${choice.key || humanIndex}) ${choice.name || choice.value}`; | ||
if (choice.key === value.toLowerCase() || String(humanIndex) === value) { | ||
.map((choice) => { | ||
if (core_1.Separator.isSeparator(choice)) { | ||
return ` ${choice.separator}`; | ||
} | ||
index += 1; | ||
const line = ` ${choice.key || index}) ${choice.name || choice.value}`; | ||
if (choice.key === value.toLowerCase() || String(index) === value) { | ||
return chalk_1.default.cyan(line); | ||
@@ -57,0 +65,0 @@ } |
{ | ||
"name": "@inquirer/rawlist", | ||
"version": "1.0.7", | ||
"version": "1.1.0", | ||
"description": "Inquirer rawlist prompt", | ||
@@ -57,3 +57,3 @@ "main": "./dist/cjs/index.js", | ||
"dependencies": { | ||
"@inquirer/core": "^1.1.3", | ||
"@inquirer/core": "^1.2.0", | ||
"@inquirer/type": "^1.0.3", | ||
@@ -87,3 +87,3 @@ "chalk": "^4.1.2" | ||
}, | ||
"gitHead": "fdfa190cb12f2e28299878f433b0a9a15befc535" | ||
"gitHead": "f3a176d916fe26038c9fb57f1ab485aa79c053ce" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13802
216
Updated@inquirer/core@^1.2.0