-
Notifications
You must be signed in to change notification settings - Fork 25
/
example.js
62 lines (46 loc) · 1.38 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Checkbox Plus Example
*
* @author Mohammad Fares <[email protected]>
*/
var inquirer = require('inquirer');
var fuzzy = require('fuzzy');
inquirer.registerPrompt('checkbox-plus', require('./index'));
var colors = [
{name: 'The red color', value: 'red', short: 'red', disabled: false},
{name: 'The blue color', value: 'blue', short: 'blue', disabled: true},
{name: 'The green color', value: 'green', short: 'green', disabled: false},
{name: 'The yellow color', value: 'yellow', short: 'yellow', disabled: false},
{name: 'The black color', value: 'black', short: 'black', disabled: false}
];
inquirer.prompt([{
type: 'checkbox-plus',
name: 'colors',
message: 'Enter colors',
pageSize: 10,
highlight: true,
searchable: true,
default: ['yellow', 'red', {name: 'black'}],
validate: function(answer) {
if (answer.length == 0) {
return 'You must choose at least one color.';
}
return true;
},
source: function(answersSoFar, input) {
input = input || '';
return new Promise(function(resolve) {
var fuzzyResult = fuzzy.filter(input, colors, {
extract: function(item) {
return item['name'];
}
});
var data = fuzzyResult.map(function(element) {
return element.original;
});
resolve(data);
});
}
}]).then(function(answers) {
console.log(answers.colors);
});