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 🙏

© 2026 – Pkg Stats / Ryan Hefner

chinstrap-engine

v0.8.0

Published

The chinstrap rendering engine.

Downloads

26

Readme

Chinstrap

Note that Chinstrap has no dependencies in the compiler.


module.exports = ( ->

	class Chinstrap

Basic Setup

Value: open

The opener is the string pattern that marks the beginning of a code block. Default is {{

Value: close

The closer is the string pattern taht marks the end of a code block. Default is }}.


		open: "{{"
		close: "}}"

Methods: setOpen and setClose

Two methods to override the opne and close values.


		setOpen: (@open) ->

		setClose: (@close) ->

Main Execution Code

Method: merge

The main method to call when using Chinstrap.

Receives three arguments:


		merge: (template, data, returnSource) ->
			returnSource = typeof returnSource isnt 'undefined' and returnSource
			template = @render(template)
			fn = new Function("obj", template)
			if returnSource then str else fn(data)

Method: render (String str)

Workhorse method; converts the template into a function.


		render: (str) ->
			str = @stripWhiteSpace(str)
			str = @replaceOpenChars(str)
			str = str.replace(/((^|\}\})[^\t]*)'/g, "$1\r")
			str = @replaceQmarkWithIfOpen(str)
			str = str.replace(/\t\s?\@\=(.*?)\}\}/g, "\titerator=$1;\n}}")
			str = str.replace(/\t\s?WHILE(.*?)\}\}/g, "\twhile ($1) {\n}}")
			str = str.replace(/\t\s?\/WHILE(.*?)\}\}/g, "\t}\n}}")
			str = str.replace(/\t\s?FOR(.*?)\}\}/g, "\tfor ($1) {\n}}")
			str = str.replace(/\t\s?%(.*?)\}\}/g,"', this.merge($1), '")
			str = str.replace(/\t\s?\/FOR(.*?)\}\}/g, "\t}\n}}")
			str = str.replace(/\t\s?(IF|\?)(.*?)\}\}/g, "\tif (value($2)) {\n}}")
			str = str.replace(/\t\s?\/(IF|\?)(.*?)\}\}/g, "\t}\n}}")
			str = str.replace(/\t\s?(\-\?|ELSEIF)(.*?)\}\}/g, "\t} else if (value($2)) {\n}}")
			str = str.replace(/\t\s?(\-|ELSE)(.*?)\}\}/g, "\t} else {\n}}")
			str = str.replace(/\@\@/g, "iterator")
			str = str.replace(/\@/g, "iterator.")
			str = str.split("\t").join("');\n")
			str = str.split(@close).join("p.push('")
			str = str.split("\r").join("\\'")
			str = "\nvar p=[],iterator = {},print=function(){p.push.apply(p,arguments);},value = function(val){if (typeof val == 'function') {return val.apply(iterator);} else {return val;}};\nwith(config){\np.push('" + str + "');\n}\nreturn p.join('');\n"

String Manipulation Functions

Method: stripWhiteSpace

The conceit of the Resig system is to remove lots of white space characters, and then use those characters as drop-ins for action items.

So step one is to remove tabs and returns, and replace them with a blank space.


		stripWhiteSpace: (str) -> str.replace(/[\r\t\n]/g, " ")

Method: replaceOpenChars

Chinstrap executes snippets of code that live between an open and close character. The default opener is "{{".

Now replace the open character (default "{{") with a tab character ("\t"). We'll use this to put the function back together later.


		replaceOpenChars: (str) -> str.split(@open).join("\t")

Replace ? with if statement

You can write an if statement in two alternate styles.


		replaceQmarkWithIfOpen: (str) -> str.replace(/\t\s?=(.*?)\}\}/g, "',value($1),'")

		compileWhileOpen: (str) ->

		compileWhileClose: (str) ->

		compileForOpen: (str) ->

		compileForClose: (str) ->

	module.exports = new Chinstrap()
)()