Some useful utilities for <a href="https://github.com/niclashoyer/onion">onion</a>.

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) ->
is 42
middleware = (x) ->
skin = filter rulemiddleware
onion.stack "foo"skin
onion.innermost = ->
return 0
console.log onion.peelFor "foo"23
console.log onion.peelFor "foo"42