Some useful utilities for [onion](https://github.com/niclashoyer/onion).

npm install onion.utils
12 downloads in the last month

Onion Utils

Some useful utilities for onion.


The filter middleware can be used to run a middleware under certain conditions. The first argument of filter has to be a rule which is a function that returns a boolean value. If the function returns true the middleware will be executed, otherwise it will be left out.


Simple example. The Onion should return 42 if, and only if the given number is 42. Otherwise it should return 0.

Onion  = require 'onion'
utils  = require 'onion.utils'
filter = utils.filter

onion = new Onion

rule = (x) ->
    x is 42

middleware = (x) ->

skin = filter rule, middleware

onion.stack "foo", skin
onion.innermost = ->
    return 0

console.log onion.peelFor "foo", 23
console.log onion.peelFor "foo", 42
npm loves you