superprompt
Version:
Superprompt is a commandline prompting tool with different prompt types
83 lines (78 loc) • 5.62 kB
JavaScript
module.exports.__fsLocationMap = [[1, 8, 1, 7], [1, 18, 1, 22], [1, 8, 1, 32], [3, 8, 2, 1], [3, 14, 2, 7], [4, 5, 3, 3], [5, 9, 4, 5], [5, 14, 4, 10], [5, 26, 4, 22], [6, 9, 5, 5], [6, 14, 5, 10], [6, 29, 5, 25], [7, 9, 6, 5], [7, 14, 6, 10], [7, 28, 6, 24], [10, 5, 9, 3], [10, 10, 9, 8], [11, 9, 10, 5], [11, 14, 10, 10], [11, 24, 10, 20], [11, 29, 10, 25], [12, 9, 11, 5], [12, 16, 11, 12], [15, 5, 14, 3], [16, 9, 15, 5], [16, 14, 15, 10], [17, 9, 16, 5], [17, 16, 16, 12], [17, 20, 16, 16], [17, 28, 16, 24], [17, 29, 16, 25], [17, 38, 16, 34], [18, 13, 17, 7], [18, 19, 17, 13], [18, 26, 17, 20], [19, 17, 18, 9], [19, 23, 18, 15], [19, 34, 18, 26], [19, 39, 18, 31], [19, 49, 18, 41], [20, 17, 19, 9], [20, 20, 19, 13], [20, 21, 19, 14], [21, 21, 20, 11], [21, 29, 20, 19], [21, 34, 20, 24], [22, 21, 21, 11], [22, 28, 21, 18], [25, 17, 23, 9], [25, 20, 23, 13], [25, 27, 24, 12], [25, 37, 25, 12], [25, 52, 26, 12], [25, 57, 26, 17], [25, 67, 26, 27], [26, 21, 27, 13], [26, 27, 27, 19], [26, 38, 27, 30], [26, 45, 27, 37], [26, 54, 27, 46], [26, 63, 27, 55], [26, 76, 27, 68], [26, 85, 27, 77], [26, 90, 27, 82], [26, 95, 27, 87], [26, 106, 27, 98], [26, 107, 27, 99], [26, 108, 27, 100], [26, 117, 27, 109], [28, 21, 28, 13], [28, 24, 28, 17], [28, 25, 28, 18], [29, 25, 29, 15], [30, 25, 30, 15], [30, 32, 30, 22], [34, 17, 33, 9], [34, 22, 33, 14], [34, 27, 33, 19], [34, 37, 33, 29], [34, 38, 33, 30], [34, 43, 33, 35], [35, 21, 34, 13], [35, 24, 34, 17], [36, 25, 35, 15], [36, 31, 35, 21], [39, 21, 37, 13], [39, 26, 37, 18], [39, 39, 37, 31], [39, 49, 37, 41], [40, 21, 38, 13], [44, 13, 41, 7], [48, 5, 45, 5], [48, 11, 45, 11], [48, 21, 45, 21], [49, 9, 46, 7], [49, 15, 46, 13], [49, 22, 46, 20], [49, 26, 46, 24], [49, 31, 46, 29], [50, 9, 47, 7], [50, 12, 47, 11], [50, 21, 47, 20], [50, 30, 47, 29], [51, 13, 48, 9], [51, 20, 48, 16], [51, 25, 48, 21], [51, 31, 48, 27], [52, 9, 49, 9], [53, 13, 50, 9], [53, 20, 50, 16], [53, 25, 50, 21], [53, 32, 50, 28], [56, 5, 54, 5], [56, 19, 54, 19], [56, 29, 54, 29], [57, 9, 55, 7], [57, 12, 55, 11], [57, 21, 55, 20], [57, 30, 55, 29], [58, 13, 56, 9], [58, 16, 56, 13], [58, 21, 56, 18], [58, 34, 56, 31], [58, 39, 56, 36], [59, 17, 57, 11], [59, 22, 57, 16], [59, 30, 57, 24], [59, 39, 57, 33], [59, 47, 57, 41], [60, 13, 58, 11], [60, 18, 58, 20], [60, 23, 58, 25], [60, 35, 58, 37], [60, 40, 58, 42], [61, 17, 59, 11], [61, 22, 59, 16], [61, 30, 59, 24], [61, 39, 59, 33], [61, 47, 59, 41], [62, 13, 60, 11], [63, 17, 61, 11], [63, 22, 61, 16], [63, 32, 61, 26], [63, 40, 61, 34], [65, 9, 63, 9], [65, 14, 63, 18], [65, 23, 63, 27], [65, 32, 63, 36], [66, 13, 64, 9], [66, 16, 64, 13], [66, 27, 64, 24], [67, 17, 65, 11], [67, 24, 65, 18], [69, 13, 67, 9], [69, 16, 67, 13], [69, 17, 67, 14], [69, 22, 67, 19], [69, 30, 67, 27], [69, 39, 67, 36], [70, 17, 68, 11], [70, 22, 68, 16], [70, 30, 68, 24], [70, 39, 68, 33], [70, 47, 68, 41], [73, 13, 70, 9], [73, 18, 71, 12], [73, 26, 71, 20], [73, 35, 71, 29], [73, 41, 72, 12], [73, 46, 72, 17], [74, 13, 73, 9], [74, 18, 73, 14], [74, 28, 73, 24], [74, 36, 73, 32], [75, 9, 74, 11], [75, 14, 74, 20], [75, 23, 74, 29], [75, 32, 74, 38], [76, 13, 75, 11], [76, 18, 75, 16], [76, 26, 75, 24], [76, 35, 75, 33], [76, 43, 75, 41], [76, 54, 75, 52], [76, 62, 75, 60], [77, 9, 76, 11], [78, 13, 77, 11], [78, 18, 77, 16], [78, 26, 77, 24], [78, 35, 77, 33], [78, 43, 77, 41], [3, 14, 81, 16], [3, 14, 81, 30]];
const Read = require('./Read').Read;
class Superprompt {
constructor () {
this.questions = [ ];
this.truthyValues = /y|yes|on|true|enabled/i;
this.falsyValues = /n|no|off|false|disabled/i;
}
ask (question) {
this.questions.push(question);
return this;
}
prompt () {
this.answers = {};
return new Promise((resolve, reject) => {
const next = () => {
const question = this.questions.shift();
if (!question) {
resolve(this.answers);
return null;
}
if (Object
.prototype
.hasOwnProperty
.call(question, 'only')) {
const showNext = typeof question.only === 'function' ? question.only(this.answers) : !!question.only;
if (!showNext) {
next();
return null;
}
}
this.read(question, (err, answer) => {
if (err) {
throw err;
}
this.handleAnswer(question, answer);
next();
});
};
next();
});
}
read (question, fn) {
const read = new Read(question);
if (question.type === 'input') {
return read.input(fn);
} else {
return read.prompt(fn);
}
}
handleAnswer (question, answer) {
if (question.type === 'boolean') {
if (this.truthyValues.test(answer)) {
this.answers[question.name] = true;
} else if (this.falsyValues.test(answer)) {
this.answers[question.name] = false;
} else {
this.questions.unshift(question);
}
} else if (question.type === 'array') {
if (answer === '') {
return null;
}
if (!this.answers[question.name]) {
this.answers[question.name] = [ ];
}
this
.answers[question.name]
.push(answer);
this.questions.unshift(question);
} else if (question.type === 'number') {
this.answers[question.name] = parseFloat(answer, 10);
} else {
this.answers[question.name] = answer;
}
}
}
module.exports.Superprompt = Superprompt;