execute command for math and logic calculations

This commit is contained in:
Baipyrus 2023-01-13 12:05:17 +01:00
parent c66d7c7386
commit a11b93480d

View File

@ -5,4 +5,24 @@ function cmd_help() {
function cmd_clear() {
window.location.reload();
return "";
}
function cmd_exec(input) {
if (input === undefined)
return "You must enter parameters!";
const str = input.join(' ');
if (/[',:;a-zA-Z]/.test(str) || str === "")
return "Invalid input!";
const chars = str.split('').filter(e => {
const code = e.charCodeAt(0);
const s = code === 32;
const a = code > 36;
const b = code < 63;
const c = code === 94;
const d = code === 124;
return !(s || a && b || c || d);
});
if (chars.length > 0)
return "Invalid input!";
return (new Function(`return ${str}`))();
}