Skip to content

iff

Source Code | Documentation

See also: iffElse unless predicates

Execute one or another series of hooks depending on a sync or async predicate.

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

Type declaration

ts
export interface IffHook<H extends HookContext = HookContext>
  extends HookFunction<H> {
  else(...hooks: HookFunction<H>[]): HookFunction<H>
}
/**
 * Execute one or another series of hooks depending on a sync or async predicate.
 *
 * @see https://utils.feathersjs.com/hooks/iff.html
 */
export declare function iff<H extends HookContext = HookContext>(
  predicate: boolean | PredicateFn<H>,
  ...hooks: HookFunction<H>[]
): IffHook<H>
export { iff as when }
ArgumentTypeDescription
predicateboolean | PredicateFn<H>
hooksHookFunction<H>[]
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.