Skip to content

parseAsIndex

const parseAsIndex: Parser<number>;

Defined in: tanstack/core/built-in-parsers.ts:135

Page index: the URL is 1-indexed, state is 0-indexed (?page=1 ⇄ 0). Fits TanStack Table’s pageIndex while keeping human-friendly URLs.

import { parseAsIndex } from "@xtandard/lib/tanstack";
parseAsIndex.parse("1"); // → 0
parseAsIndex.parse("3"); // → 2
parseAsIndex.serialize(0); // → "1"
const pageIndex = parseAsIndex.withDefault(0); // no ?page → 0