From 2d500f68b70631c08ab74bc99b307484f3d4f2d8 Mon Sep 17 00:00:00 2001 From: Reyn Date: Fri, 20 Dec 2024 23:29:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=B4=E6=95=B0=E3=80=81?= =?UTF-8?q?=E6=95=B0=E5=80=BC=E3=80=81=E9=80=89=E6=8B=A9=E5=99=A8=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rule.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Rule.ts b/Rule.ts index 328081b..fdfa7d2 100644 --- a/Rule.ts +++ b/Rule.ts @@ -30,9 +30,12 @@ function IntegerParser(text: string): number { if (typeof text === "string") { text = text.replace(/\D/g, ""); // 去除所有非数字的字符 } + if (text.length == 0) { + text = "0"; + } let ret = parseInt(text); if (isNaN(ret)) { - throw new Error("[I] Not a number"); + throw new Error(`[I] "${text}" Not a number`); } return ret; } @@ -48,9 +51,12 @@ function NumberParser(text: string): number { if (typeof text === "string") { text = text.replace(/[^\d.]/g, ""); // 去除所有非数字和非小数点的字符 } + if (text.length == 0) { + text = "0"; + } let ret = parseFloat(text); if (isNaN(ret)) { - throw new Error("[N] Not a number"); + throw new Error(`[I] "${text}" Not a number`); } return ret; } @@ -79,11 +85,11 @@ function PickParser(text: string, params?: string): number { values[v] = i; }); if (text == undefined) { - throw new Error("[OP] Not a valid option"); + throw new Error(`[OP] "${text}" Not a valid option`); } let ret = values[text]; if (ret === undefined) { - throw new Error("[OP] Not a valid option"); + throw new Error(`[OP] "${text}" Not a valid option`); } return ret; }