npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tamarack

v0.2.2

Published

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

Downloads

6

Readme

Tamarack(.js)

Build Status NPM version

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.

Installation

Node

npm install tamarack

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

Usage

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 = {
	executeSync: function(input, next) {
		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 = {
	executeSync: function(input, next) {
		input = input.replace(/ur mom sux/gi, 'Let\'s agree to disagree.');
		return next(input);
	}
};

Asynchronous Pipelines

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 = {
	execute: function(input, next, callback) {
		input += this.word;
		next(input, callback);
	}
};

And then how you use it in a pipeline:

new Pipeline()
	.add(new AppendWord(' world'))
	.andFinally(function(input, callback) {
		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(input, next, callback) {
	var self = this;
	next(input, function(result) {
		result += self.word;
		callback(result);
	});
}

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

Development

git clone [email protected]: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.