diff --git a/src/utils/string.test.ts b/src/utils/string.test.ts index 7c079b315..f59f3d850 100644 --- a/src/utils/string.test.ts +++ b/src/utils/string.test.ts @@ -1,5 +1,6 @@ -import { it, describe, expect } from "vitest"; -import { parseNumericString } from "./string"; +import { describe, expect, it } from 'vitest' + +import { parseNumericString } from './string' describe('parseNumericString', () => { it('should return an integer', () => { @@ -22,7 +23,7 @@ describe('parseNumericString', () => { expect(parseNumericString('-123')).toBe(null) }) - it('should return null for a negative number', () => { + it('should return null for a invalid number', () => { expect(parseNumericString('1a23')).toBe(null) }) -}) \ No newline at end of file +}) diff --git a/src/utils/string.ts b/src/utils/string.ts index c2467d224..86a0e4309 100644 --- a/src/utils/string.ts +++ b/src/utils/string.ts @@ -1,9 +1,11 @@ -export const parseNumericString = (time: string | null): number | null => { - if (!time) return null +export const parseNumericString = (value: string | null): number | null => { + if (!value) return null - if (typeof +time === 'number' && !Number.isNaN(+time)) { - return +time + const parsed = Number(value) + + if (typeof parsed !== 'number' || Number.isNaN(parsed) || parsed < 0) { + return null } - return null + return parseInt(String(parsed)) }