Micro framework for working with the chain of responsibility pattern. Port of the Tamarack .NET library.


This is a NodeJS port of the similarly named framework for .NET, written by Mike Valenty. The documentation on that page is more verbose than the stuff on this page. That's because the APIs are pretty much identical except for the case of the first letter in the functions. And there's less angle brackets in the JavaScript version.

npm install tamarack

###Browser Reference tamarack.min.js somewhere, and use window.tamarack.

You start with a Pipeline. Pipelines contain filters. In the dynamic, non-type-safe JavaScript world, a filter is just an object that has an executeSync function on it. Here is the simplest filter of them all:

var simpleFilter = {
    executeSyncfunction(inputnext) {
        return next(input);
var Pipeline = require('tamarack').Pipeline;
function createNewPost(post) {
    var pipeline = new Pipeline()
        .add(new CanonicalizeHtml())
        .add(new StripMaliciousTags())
        .add(new RemoveJavaScript())
        .add(new RewriteProfanity())
        .add(new GuardAgainstDoublePost())
        .andFinally(function(post) { return repository.saveSync(post); });
    return pipeline.executeSync(post);

Here's what one of these filters might look like:

function RewriteProfanity() {}
RewriteProfanity.prototype = {
    executeSyncfunction(inputnext) {
        input = input.replace(/ur mom sux/gi, 'Let\'s agree to disagree.');
        return next(input);

Two things to do when handling asynchronous filters and pipelines:

  1. Add an execute(input, next, callback) function to your filter
  2. Call execute(input, null, callback) on the pipeline

For example, here's an asynchronous filter:

function AppendWord(word) {
    this.word = word;
AppendWord.prototype = {
    executefunction(inputnextcallback) {
        input += this.word;
        next(input, callback);

And then how you use it in a pipeline:

new Pipeline()
    .add(new AppendWord(' world'))
    .andFinally(function(inputcallback) {
        callback(input + '!');
    .execute('Hello', null, function(result) {
        console.log(result); //"Hello world!" 

If you want to modify the output using an asynchronous filter, AppendWord.prototype.execute would become:

function(inputnextcallback) {
    var self = this;
    next(input, function(result) {
        result += self.word;

The result after executing the pipeline as above would be Hello !world.

git clone git@github.com:tmont/tamarackjs.git
cd tamarackjs
npm install
node_modules/.bin/grunt test
  • Run node_modules/.bin/grunt build to create the minified browser version of tamarack.
  • Run node_modules/.bin/grunt coverage for code coverage.
  • Run node_modules/.bin/grunt release to prepare a release build.