Skip to content

Commit

Permalink
fix(api): fix pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
ybw0014 committed Jan 24, 2024
1 parent 96caa26 commit 47032de
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions api/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { Ctx } from '~/types/hono'

export function parseNumber(str: string | undefined, defaultVal: number, min = 1, max = Math.max()) {
if (str === null || str === undefined) return defaultVal
export function parseNumber(str: string | undefined, defaultVal: number, min = 1, max = Number.MAX_SAFE_INTEGER) {
let num = parseInt(str)
if (Number.isNaN(num)) return defaultVal
if (!Number.isInteger(num)) return defaultVal
if (num < min) num = min
if (num > max) num = max
return num
Expand Down

0 comments on commit 47032de

Please sign in to comment.