Skip to content

iffElse

Source Code | Documentation

See also: iff unless predicates

Execute one array of hooks or another based on a sync or async predicate.

ts
  import { 
iffElse
} from 'feathers-utils/hooks';

Type declaration

ts
/**
 * Execute one array of hooks or another based on a sync or async predicate.
 *
 * @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
ArgumentTypeDescription
predicateboolean | PredicateFn<H>
trueHookHookFunction<H> | HookFunction<H>[] | undefined
falseHookHookFunction<H> | HookFunction<H>[] | undefined
typemethodsmulti
before, afterallyes

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.

every

Return the and of a series of sync or async predicate functions.

isContext

Check if the context matches the given options.

isMulti

util to check if a hook is a multi hook:

  • find: true
  • get: false
  • create: context.data is an array
  • update: false
  • patch: context.id == null
  • remove: context.id == null
isPaginated

util to check if a hook is a paginated hook using getPaginate

isProvider

Check which transport provided the service call.

not

Negate a predicate function.

shouldSkip

Util to detect if a hook should be skipped

Checks the params.skipHooks array for the hook name, type, or 'all'.

some

Return the or of a series of sync or async predicate functions.

Released under the MIT License.