Skip to content

Commit 9570b78

Browse files
committed
Implement string casting in isNumber
1 parent 5b2fd72 commit 9570b78

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "strontium",
3-
"version": "2.6.1",
3+
"version": "2.6.2",
44
"description": "Strontium is a TypeScript toolkit for High Performance API servers built for Production not Projects.",
55
"main": "lib/src/index.js",
66
"types": "lib/src/index.d.ts",

src/validation/drivers/validators/isNumber.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import { ValidationError } from "../../../errors/http/ValidationError"
22

33
export const isNumber = (input?: unknown): number => {
4-
if (typeof input === "number") {
4+
if (typeof input === "number" && !isNaN(input)) {
55
return input
66
}
77

8+
if (typeof input === "string") {
9+
let parsedNumber = Number(input)
10+
11+
if (!isNaN(parsedNumber)) {
12+
return parsedNumber
13+
}
14+
}
15+
816
throw new ValidationError(
917
"IS_NUMBER",
1018
"Value not a number",

0 commit comments

Comments
 (0)