Skip to content

unless

hooks
Source Code | Documentation

See also: hooks/iff hooks/iffElse predicates

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.

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

Example

ts
import { unless, isProvider } from 'feathers-utils/predicates'

app.service('users').hooks({
  before: { all: [unless(isProvider('server'), authenticate('jwt'))] }
})

Type declaration

Show Type Declarations
ts
/**
 * 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.
 *
 * @example
 * ```ts
 *
 *
 * app.service('users').hooks({
 *   before: { all: [unless(isProvider('server'), authenticate('jwt'))] }
 * })
 * ```
 *
 * @see https://utils.feathersjs.com/hooks/unless.html
 */
export declare function unless<H extends HookContext = HookContext>(
  predicate: boolean | PredicateFn,
  ...hooks: HookFunction<H>[]
): (this: any, ctx: HookContext) => any
ArgumentTypeDescription
predicateboolean | PredicateFn
hooksHookFunction<H>[]
typemethodsmulti
before, afterallyes

Released under the MIT License.