Skip to content

isPaginated

predicates
Source Code | Documentation

See also: utils/getPaginate

Checks if the current find operation is paginated by inspecting params.paginate and the service's pagination options via getPaginate. Returns false for all methods other than find or when pagination is disabled.

ts
  import { 
isPaginated
} from 'feathers-utils/predicates';

Example

ts
import { iff, isPaginated } from 'feathers-utils/predicates'

app.service('users').hooks({
  after: { find: [iff(isPaginated, addTotalCountHeader())] }
})

Hooks for predicates

HookDescription
iff

Conditionally executes a series of hooks when the predicate is truthy. The predicate can be a boolean value or a sync/async function. Supports an .else(...) chain for the falsy branch. Also exported as when.

iffElse

Executes one array of hooks when the predicate is truthy, or another array when it is falsy. The predicate can be a boolean or a sync/async function. Unlike iff, both branches are provided upfront without chaining.

skippable

Wraps a hook so it can be conditionally skipped based on a predicate. When the predicate returns true, the wrapped hook is skipped entirely. Commonly used with shouldSkip and addSkip for runtime hook control.

throwIf

Throws a BadRequest error when the given predicate function returns true. The predicate receives the hook context and can be async. Useful for validating conditions before proceeding with a request.

unless

Executes a series of hooks when the predicate is falsy --- the inverse of iff. The predicate can be a boolean or a sync/async function. Useful for applying hooks to all contexts except those matching a condition.

Type declaration

Show Type Declarations
ts
/**
 * Checks if the current `find` operation is paginated by inspecting
 * `params.paginate` and the service's pagination options via `getPaginate`.
 * Returns `false` for all methods other than `find` or when pagination is disabled.
 *
 * @example
 * ```ts
 *
 *
 * app.service('users').hooks({
 *   after: { find: [iff(isPaginated, addTotalCountHeader())] }
 * })
 * ```
 *
 * @see https://utils.feathersjs.com/predicates/is-paginated.html
 */
export declare const isPaginated: <H extends HookContext = HookContext>(
  context: H,
) => boolean
ArgumentTypeDescription
contextH

Released under the MIT License.