node package manager
Painless code sharing. npm Orgs help your team discover, share, and reuse code. Create a free org »


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