mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-11 03:38:02 +00:00
21 lines
522 B
TypeScript
21 lines
522 B
TypeScript
export const normalizeDocumentTargetPage = (page: unknown): number | null => {
|
|
if (page === undefined || page === null || page === '') {
|
|
return null;
|
|
}
|
|
|
|
const value = Number(page);
|
|
if (!Number.isFinite(value)) {
|
|
return null;
|
|
}
|
|
|
|
const targetPage = Math.trunc(value);
|
|
return targetPage > 0 ? targetPage : null;
|
|
};
|
|
|
|
export const clampDocumentTargetPage = (page: number | null | undefined, pageCount: number) => {
|
|
if (!page || pageCount < 1) {
|
|
return null;
|
|
}
|
|
|
|
return Math.min(Math.max(1, page), pageCount);
|
|
};
|