-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
50 lines (38 loc) · 1020 Bytes
/
index.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
'use strict';
const Prompt = require('prompt-base');
const cyan = require('ansi-cyan');
/**
* Create a new `Confirm` prompt, with the given `question`.
*/
function Confirm(/*question, answers, rl*/) {
Prompt.apply(this, arguments);
this.originalDefault = this.question.default !== false;
this.question.default = this.originalDefault === true ? 'Y/n' : 'y/N';
this.question.type = 'confirm';
}
/**
* Inherit `Prompt`
*/
Prompt.extend(Confirm);
/**
* Render final selected answer when "line" ("enter" keypress)
* is emitted
*/
Confirm.prototype.renderAnswer = function() {
return cyan(this.getAnswer(this.answer) ? 'Yes' : 'No');
};
/**
* Get the answer to use. Returns true if `input` is a truthy value.
* @param {String} `input`
* @return {Boolean}
*/
Confirm.prototype.getAnswer = function(input) {
if (input != null && input !== '') {
return /^(y(es)?|true)$/i.test(String(input).trim());
}
return this.originalDefault;
};
/**
* Module exports
*/
module.exports = Confirm;