Skip to content

parsePaginationParams

function parsePaginationParams(source, options?): PaginationInput;

Defined in: pagination-params.ts:58

Parse untrusted transport params (query string, parsed body…) into a PaginationInput, with sane defaults and clamping.

Style detection, in precedence order:

  1. cursor — cursor, after or before present (before ⇒ backward)
  2. offset — offset or skip present (limit/take set the size)
  3. page — page present (page_size/pageSize/per_page/perPage/size)
  4. otherwise the fallback style with defaults
Parameter Type
source PaginationParamsSource
options? ParsePaginationParamsOptions

PaginationInput

parsePaginationParams(new URL(req.url).searchParams);
// ?page=3&per_page=25 → { type: "page", page: 3, pageSize: 25 }
// ?limit=10&offset=40 → { type: "offset", limit: 10, offset: 40 }
// ?cursor=abc&direction=backward → { type: "cursor", limit: 20, cursor: "abc", direction: "backward" }