iffElse
Source Code | DocumentationSee also: hooks/iff hooks/unless predicates
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.
import { iffElse } from 'feathers-utils/hooks';Example
import { iffElse, isProvider } from 'feathers-utils/predicates'
app.service('users').hooks({
before: {
find: [iffElse(isProvider('external'), [hook1()], [hook2()])]
}
})Type declaration
Show Type Declarations
/**
* 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.
*
* @example
* ```ts
*
*
* app.service('users').hooks({
* before: {
* find: [iffElse(isProvider('external'), [hook1()], [hook2()])]
* }
* })
* ```
*
* @see https://utils.feathersjs.com/hooks/iff-else.html
*/
export declare function iffElse<H extends HookContext = HookContext>(
predicate: boolean | PredicateFn<H>,
trueHook: HookFunction<H> | HookFunction<H>[] | undefined,
falseHook?: HookFunction<H> | HookFunction<H>[] | undefined,
): (this: any, ctx: H) => any| Argument | Type | Description |
|---|---|---|
| predicate | boolean | PredicateFn<H> | |
| trueHook | HookFunction<H> | HookFunction<H>[] | undefined | |
| falseHook | HookFunction<H> | HookFunction<H>[] | undefined |
| type | methods | multi |
|---|---|---|
| before, after | all | yes |
Predicates
'feathers-utils' provides a set of predicates that can be used with this hook. These predicates can be used to conditionally execute hooks based on the result of a predicate function.
| Predicate | Description |
|---|---|
every | Returns a predicate that is |
isContext | Returns a predicate that checks whether the hook context matches the given criteria.
You can filter by |
isMulti | Checks if the current hook context represents a multi operation.
Returns |
isPaginated | Checks if the current |
isProvider | Returns a predicate that checks the transport provider of the service call.
Matches against |
not | Negates a sync or async predicate function, inverting its boolean result. Useful for composing conditions like "not external" or "not multi". |
shouldSkip | Returns a predicate that checks |
some | Returns a predicate that is |
