inquirer2
Version:
Lighter, faster alternative to inquirer. A collection of common interactive command line user interfaces.
36 lines (30 loc) • 880 B
JavaScript
;
var utils = require('../utils/');
/**
* Choice object
* Normalize input as choice object
* @param {String|Object} `val` Choice value. If an object is passed, it should contain at least one of `value` or `name` property.
* @api public
*/
var Choice = module.exports = function(val, answers) {
// Don't process Choice and Separator object
if (val instanceof Choice || val.type === 'separator') {
return val;
}
if (typeof val === 'string') {
this.name = val;
this.value = val;
this.short = val;
} else {
utils.extend(this, val, {
name: val.name || val.value,
value: val.hasOwnProperty('value') ? val.value : val.name,
short: val.short || val.name || val.value
});
}
if (typeof val.disabled === 'function') {
this.disabled = val.disabled(answers);
} else {
this.disabled = val.disabled;
}
};