-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
35 lines (29 loc) · 763 Bytes
/
util.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
import readline from "readline-sync"
export function cmdGetNumber(validate) {
for (; ;) {
let key = Number(readline.question("> "))
if (key != key) {
console.log("Insert a number!")
continue;
}
if (validate(key)) {
return key;
} else console.log("Data not accepted, check if it's within bounds!")
}
}
export function cmdGetString(validate) {
for (; ;) {
let key = readline.question("> ").toString()
if (key.length == 0) {
console.log("Please type the required data.")
continue;
}
if (validate(key)) {
return key;
}
else {
console.log("Data not accepted, please type what the program asks above")
}
}
}
export const Clean4FS = str => str.toLowerCase().replaceAll(/[\\\/\[\]\:\¦\<\>\+\=\;\,\*\?\"]+/gm, "_");