From a11b93480dd35e1ab03981c36bb9f451e6e786bb Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Fri, 13 Jan 2023 12:05:17 +0100 Subject: [PATCH] execute command for math and logic calculations --- js/commands.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/js/commands.js b/js/commands.js index 123c471..7acf81b 100644 --- a/js/commands.js +++ b/js/commands.js @@ -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}`))(); } \ No newline at end of file