Updated functions

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2019-12-05 09:56:41 +01:00
parent b61cb6b646
commit 9b85d0a06a
No known key found for this signature in database
GPG Key ID: B143FF27EF555D16

View File

@ -1,3 +1,4 @@
const evil = eval
/** /**
* Eval string starting with `run:` * Eval string starting with `run:`
* *
@ -8,7 +9,7 @@
export function evalF(str: string, callback?: (str: string) => void): boolean { export function evalF(str: string, callback?: (str: string) => void): boolean {
if (str && str.startsWith("run:")) { if (str && str.startsWith("run:")) {
let tmp = str.split("run:")[1] let tmp = str.split("run:")[1]
const res = eval(tmp) const res = evil(tmp)
if (res && callback) callback(res) if (res && callback) callback(res)
return true return true
} }
@ -21,7 +22,8 @@ export function evalF(str: string, callback?: (str: string) => void): boolean {
* @param str the string to transform * @param str the string to transform
*/ */
export function toNumber(str: any): number|undefined { export function toNumber(str: any): number|undefined {
if (str !== 0 && (str === "" || str === undefined || typeof(str) === "boolean")) return undefined if (typeof str === "number") return str
if ((str === "" || str === undefined || typeof(str) === "boolean")) return undefined
// return undefined if it must be shown as string // return undefined if it must be shown as string
// console.log("toNumber", str) // console.log("toNumber", str)
if ((str.startsWith("0") || str.startsWith("+")) && str.length > 1) return undefined if ((str.startsWith("0") || str.startsWith("+")) && str.length > 1) return undefined
@ -38,6 +40,7 @@ export function isNumber(el: any): boolean {
} }
export function toBoolean(str: any): boolean|undefined { export function toBoolean(str: any): boolean|undefined {
if (typeof str === "boolean") return str
if (str === "true") return true if (str === "true") return true
if (str === "false") return false if (str === "false") return false
return undefined return undefined