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

brown

v1.1.28

Published

Ultra-extendable Mustache-ish template engine on steroids in 620 gzipped kilobytes, need nothing more!

Downloads

25

Readme

Mustache-ish but clean template engine on steroids in 846 gzipped kilobytes

Usage

$ npm install brown

or in the browser:

<script type='text/javascript' src='brown.min.js'></script>

Simple

brown.render( "hello {{foo.bar}}", { 
  foo: {
    bar: "world" 
  } 
});

outputs:

hello world

Functions

Create a fullfledged template engine by adding functions:

brown.encode = function(key,type) {
  var html = this[key] || '';
  return  type == "html" ?
          String(html).replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#39;').replace(/</g, '&lt;').replace(/>/g, '&gt;') :
          html
};

brown.render( 'a href="{{href}}" onclick="{{encode:label:html}}"': "{{label}}", {
  href="/", 
  label:"my \"label\""} 
});

outputs:

<div>
  <ul>
    <li>
      <a href="/" onclick="my &quot;label&quot;">my "label"</a>
    </li>
  </ul>
</div>

If / Else / Looping

Need more? See brown-ext-basic for if/foreach/filter/loop-functionality.

Generate xml/html from jsonportable JADE

ϐrown can be monkeypatched, to automatically produce xml-trees from json (like JADE), see this coffeescript example:

json = 
  ul: 
    li: 'a href="{{foo}}": "Click me"

brown.render json,{ foo: "/" }

outputs:

<ul>
  <li>
    <a href="/">Click me </a>
  </li>
</ul>

How? Simple, by just monkeypatching ϐrown with json-dsl. See coffeescript / JS examples.

Commandline util

Use as a commandline generator (install using npm install -g ) :

  $ brown
    Usage: brown <string|file> [jsonstring|jsonfile]

  examples:
          $ brown 'foo {{foo}}' '{"foo":"world"}'
          $ brown foo.html data.json

Goals / Philosophy

  • lightweight and extendable
  • monkeypatchable syntax
  • mustache without the noise and weight (mustache is a whopping 97k and pretty slow)

I got a lot of projects using mustache. The mustache syntax can easily get really noisy, and annoying because of absense of function arguments. Brown is a way to slowly abandon the noisy syntax, and replace it with readable functions.

Hence the brown-ext-basic extension to easily convert it to brown syntax:

| | mustache | brown | |--------------------|-------------------------------------------------|-------------------------------------------------| | array iteration | {{#array}} {{.}} {{/array} | {{foreach:items:itemtemplate:"no items found"}} | | if/else | {{#foo}}{{foo}}{{/foo}}{{^foo}} no foo {{/foo}} | {{if:foo:foo:"no foo"}} | | object iteration | n/a | {{foreach:items:itemtemplate:"no items found"}} | | global functions | n/a | brown.foo = (arg1,arg2) -> return arg1+arg2 | | partial | {{ > templatename }} | {{include:templatename}} | | chaining functions | n/a | {{foo:htmlencode:uppercase}} |template functions suite | filesize | 97k | 846 bytes (gzipped)

With ϐrown as a fundament you can literally extend and overload anything.

Extentions

Roadmap

  • stability and peace