22 lines
767 B
TypeScript
22 lines
767 B
TypeScript
export const LIST_PAGE_SIZE = 50
|
|
|
|
export const LIST_PAGE_SIZE_MAX = 500
|
|
|
|
export const LIST_PAGE_SIZE_OPTIONS = [50, 100, 250, 500] as const
|
|
|
|
export type ListPageSize = (typeof LIST_PAGE_SIZE_OPTIONS)[number]
|
|
|
|
export function isListPageSize(value: number): value is ListPageSize {
|
|
return (LIST_PAGE_SIZE_OPTIONS as readonly number[]).includes(value)
|
|
}
|
|
|
|
/** Clamp persisted/UI page size to a supported API value. */
|
|
export function normalizeListPageSize(value: number): ListPageSize {
|
|
if (isListPageSize(value) && value <= LIST_PAGE_SIZE_MAX) return value
|
|
const allowed = LIST_PAGE_SIZE_OPTIONS.filter((n) => n <= LIST_PAGE_SIZE_MAX)
|
|
for (let i = allowed.length - 1; i >= 0; i--) {
|
|
if (value >= allowed[i]!) return allowed[i]!
|
|
}
|
|
return LIST_PAGE_SIZE
|
|
}
|