-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.js
More file actions
41 lines (37 loc) · 892 Bytes
/
common.js
File metadata and controls
41 lines (37 loc) · 892 Bytes
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
(function () {
const readlineSync = require('readline-sync');
default_port = 8080;
relay_internal_port = 8081;
/* Input functions */
readInt = function(canBeEmpty) {
var result = parseInt(readlineSync.question("> "));
if (typeof result === "number") {
if(isNaN(result)) {
if(canBeEmpty)
return 0;
} else
return result;
}
return readInt(canBeEmpty);
}
readString = function() {
var result = readlineSync.question("> ");
if (result.length > 0)
return result;
return readString();
}
pickOption = function(options) {
console.log();
console.log("Select an option:");
for(var i = 0; i < options.length; i++){
console.log(" " + (i + 1) + ": " + options[i]);
}
console.log();
var result = readInt(false);
if(result > 0 && result <= options.length) {
console.log();
return result - 1;
}
return pickOption(options);
}
})();