Parsing helpers for pagination-related URL params.
URL params are user input — these helpers normalize them into safe values, falling back to defaults rather than raising on tampered or malformed input.
Summary
Functions
Returns the current page from params, defaulting to 1.
Returns the page size from params, defaulting to default and clamped
to max.
Parses a positive integer from a param value, falling back to default
for anything invalid.
Functions
Returns the current page from params, defaulting to 1.
Examples
iex> Slab.Helpers.Params.page(%{"page" => "3"})
3
iex> Slab.Helpers.Params.page(%{"page" => "-1"})
1
iex> Slab.Helpers.Params.page(%{})
1
Returns the page size from params, defaulting to default and clamped
to max.
Examples
iex> Slab.Helpers.Params.per_page(%{"per_page" => "50"}, 25, 100)
50
iex> Slab.Helpers.Params.per_page(%{"per_page" => "9999"}, 25, 100)
100
iex> Slab.Helpers.Params.per_page(%{}, 25, 100)
25
Parses a positive integer from a param value, falling back to default
for anything invalid.