-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathpaginationPageSize.ts
More file actions
17 lines (15 loc) · 882 Bytes
/
Copy pathpaginationPageSize.ts
File metadata and controls
17 lines (15 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
export const RESULT_PAGE_SIZE_OPTIONS = [50, 100, 500, 1000];
export const DEFAULT_RESULT_PAGE_SIZE = 100;
export const MIN_RESULT_PAGE_SIZE = 1;
export const MAX_RESULT_PAGE_SIZE = 50000;
export function normalizeResultPageSize(value: unknown, fallback = DEFAULT_RESULT_PAGE_SIZE): number {
const fallbackValue = Number.isFinite(fallback) && fallback >= MIN_RESULT_PAGE_SIZE ? Math.min(Math.floor(fallback), MAX_RESULT_PAGE_SIZE) : DEFAULT_RESULT_PAGE_SIZE;
const parsed = Number(value);
if (!Number.isFinite(parsed)) return fallbackValue;
const rounded = Math.floor(parsed);
if (rounded < MIN_RESULT_PAGE_SIZE) return fallbackValue;
return Math.min(rounded, MAX_RESULT_PAGE_SIZE);
}
export function resultPageSizeMenuOptions(current: number): number[] {
return [...new Set([...RESULT_PAGE_SIZE_OPTIONS, normalizeResultPageSize(current)])].sort((a, b) => a - b);
}