Skip to content

Commit

Permalink
Merge branch 'FET-1689' of https://github.com/ensdomains/ens-app-v3 i…
Browse files Browse the repository at this point in the history
…nto FET-1689
  • Loading branch information
storywithoutend committed Dec 3, 2024
2 parents ef50c58 + e130f04 commit 6086c21
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/utils/string.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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)
})
})
})
12 changes: 7 additions & 5 deletions src/utils/string.ts
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 6086c21

Please sign in to comment.