This package has been deprecated

Author message:

Deprecated. Use @malijs/unless

mali-unless

0.1.1 • Public • Published

mali-unless

Conditionally add Mali middleware

npm version build status

Installation

npm install mali-unless

API

mali-unless ⇒ function

Mali unless middleware. Attach to any middleware and configure it to prevent/permit the middleware in question to be executed.

Returns: function - middleware

Param Type Description
options Object | String | RegExp | function - If string and one of Mali Call Types do middleware unless it is the specified call type - If string and not a call type, assumed to be a call name, and middleware is executed unless the call name is the name specified. Call names checks are not case sensitive. - If function it's a test function that returns true / false. If the function returns true for the given request, the middleware will not run. The function will be passed the call context. - If RegExp instance, if call name matches the regexp the middleware is skipped.
options.name String | Regex | Array A string, a RegExp or an array of any of those. If the call name matches, the middleware will not run. Call names checks are not case sensitive.
options.type String | Array A string or an array of strings. If the call type matches, the middleware will not run.
options.custom function A test function that returns true / false. If the function returns true for the given request, the middleware will not run. The function will be passed the call context.

Example

const requestId = require('mali-requestid')
const unless = require('mali-unless')
const CallType = require('mali-call-types')
const toJSON = require('mali-tojson')()
 
const rid = requestId()
rid.unless = unless
app.use(rid.unless({ name: 'SomeMethod' }))
 
toJSON.unless = unless
app.use(toJSON.unless({ type: [ CallType.DUPLEX, CallType.RESPONSE_STREAM ] }))

License

Apache-2.0

Package Sidebar

Install

npm i mali-unless

Weekly Downloads

1

Version

0.1.1

License

Apache-2.0

Last publish

Collaborators

  • bojand