Fix ToNumber

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2019-12-09 14:15:07 +01:00
parent ed5db58b89
commit 656528daa8
No known key found for this signature in database
GPG Key ID: B143FF27EF555D16

View File

@ -26,7 +26,8 @@ export function toNumber(str: any): number | undefined {
if (str === "" || typeof str !== "string") return undefined
// str is a string
if ((str.startsWith("0") || str.startsWith("+")) && str.length > 1) return undefined
const regex = new RegExp("^(0[0-9])|\\+")
if (regex.test(str) && str.length > 1) return undefined
const n = Number(str)
if (!isNaN(n)) {
return n