PhoenixKitSync.Params (PhoenixKitSync v0.2.5)

Copy Markdown View Source

Reads numbers that arrive from outside — a URL parameter, a LiveView event, a peer's WebSocket payload, an API request — where anything can turn up.

Summary

Functions

Returns value as an integer within min..max.

The largest record offset accepted from a request or a peer.

Returns value as a page number from 1 to max.

Functions

bounded_int(value, default, min, max)

@spec bounded_int(term(), integer(), integer(), integer()) :: integer()

Returns value as an integer within min..max.

A whole number (an integer, or a string holding only one, surrounding spaces aside) is clamped to the bounds; anything else — text, a fraction, "5abc", nil — gives default. Clamping also keeps a huge page or offset from overflowing the database's bigint.

max_offset()

@spec max_offset() :: pos_integer()

The largest record offset accepted from a request or a peer.

page(value, max)

@spec page(term(), pos_integer()) :: pos_integer()

Returns value as a page number from 1 to max.

Anything that is not a whole number in that range gives page 1, a page above max included: a page that far out is a broken link, not a request for the last page. The caller clamps a page past its own last page.