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

handybars

v0.4.0

Published

A light-weight templating engine inspired by Handlebars

Downloads

4

Readme

Handybars

A micro templating engine inspired by Handlebars, but with several notable changes designed to make it more versatile and significantly smaller. Handybars is not Handlebars compatible and cannot be used as a drop in replacement, but the syntax is very similar.

Note, this project is very much a work in progress, the api and behavior can and will change.

How Handybars Differs from Handlebars

  • Handybars is interpreted, not compiled (for now).
  • Each template maintains its own environment scope, there is no global scope for all templates.
  • There are no explicit helpers or partials, any function or partial in the template or environment scope can be invoked as a helper.
    • Use handybars.partial(templateText) (or import { partial } from 'handybars') to parse a partial template.
    • Use template.setPartial(name, templateText) to add a partial to a template's environment scope.
  • There is currently no support for inline partials.
  • ../ does not exist. Instead, use @parent. to access the previous scope. However, you may find you don't need this unless a local scope's keys collide with a parent scope's keys.
  • There is no built in whitespace control
  • Handybars does not support the as syntax, such as {{#each users as | user |}}
  • {{#each}} can iterate any Array, Set, Map or plain Object.
  • Blocks may contain arrays: {{#each [ '1st' '2nd' '3rd' ]}}
  • Blocks support inline value lookups: {{order[request.id].creationDate}}
  • Blocks do NOT support the value.[N] lookup syntax (note the period before the bracket)
  • The options object passed to helpers has a different structure.

Usage

npm install handybars

Usage

In CommonJS:

const handybars = require('handybars');

In ES6:

import handybars from 'handybars';

Usage:

const template = handybars("<p>{{author.first}} {{author.last}}</p>");
const html = template({
	author: {
		first: 'John',
		last: 'Doe',
	}
});

Any property can be used as a boolean truthy check.

handybars(`
	<div class="entry">
	<h1>{{book.title}}</h1>
	{{#author}}<h2>{{book.author.first}} {{book.author.last}}</h2>{{/author}}
	</div>
`)({
	book: {
		title: 'Mort'
		author: {
			first: 'Terry',
			last: 'Pratchett',
		}
	}
})

Any property that is a function will be executed as a helper.

handybars(`
	{{lcase "HELLO"}}
`)({
	lcase: (s) => s.toLowerCase(),
})

Arrays can be created inline in logic blocks

handybars(`
	{{#each [ '1st' 2 third ]}}
`)({
	third: '3rd'
})