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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@zokugun/template

v0.1.0

Published

Fast template engine forked from doT with extended and extendable tags & cache plugin

Readme

@zokugun/template

MIT licensed NPM Version Donation Donation Donation

@zokugun/template is a fast template engine forked from doT with extended and extendable tags.

Getting Started

With node previously installed:

npm install @zokugun/template
import { template } from '@zokugun/template';

var myTemplate = template.compile('It\'s nice to meet you, {{:it}}.');
console.log(myTemplate('miss White'));

Differences from doT

doT | zokugun.template | Description --- | ---------------- | ----------- {{ }} | {{| |}} | for evaluation {{= }} | {{: }} | for interpolation {{! }} | {{! }} | for interpolation with encoding {{# }} | use {{: }} | for using partials {{## #}} | {{#name(args)}} {{#}} | for defining partials {{? }} | {{? }} | for conditionals {{~ }} | {{~ }} | for array iteration | {{. }} | for object iteration | {{% }} | for while iteration | {{^ }} | for do/while iteration | {{[ ]}} | for range iteration | {{/ }} {{\ }} | for block | {{}}</code> | for escaping template |{{-- --}}` | for comments

{{ }} has been changed to {{| |}} to be able to do:

{{|
	function hello(name) {
		if(arguments.length) {
			return 'hello ' + name;
		}
		else {
			return 'hello world!';
		}
	};
|}}
{{:hello('foo')}}

API

import { template, Template } from '@zokugun/template';

The variable template is the default template compiler. It contains the tags describe below.

constructor(tags, options)

Create your own template compiler with the constructor of the Template class.

The arguments tags and options can be optionals. By default, options will be:

{
	varnames: 'it',
	strip: true,      // remove spaces in javascript code. Be careful of missing ;
	append: true      // use string concatenation or addition assignment operator
}

Example:

const custom = new Template({
	interpolate: {
		regex: /\$\{([\s\S]+?)\}/g,
		replace: function(m, code) {
			return this.cse.start + 'it.' + code + this.cse.end;
		}
	}
});

const hello = custom.compile('Hello ${firstname}');
console.log(hello({
	firstname: 'John',
	lastname: 'Doe'
}));

template.addTag(name, regex, replace)

The method addTag allow you to add new tag so he can extends the compiler. The tags are executed in alphabetic order. So its name will determine when the tag will be executed.

The function replace will be called as in str.replace(regex, replace) excepted that the variable this will an object like:

{
	cse: {
		start: string,         // start of the code
		end: string,           // end of the code
		startencode: string,   // start of the code that will be HTML escaped
		endencode: string      // end of the code that will be HTML escaped
	},
	unescape: function(str),   // unescape the code to pass from the template to the function's code
	sid: integer               // the sid for the variables' names
}

template.clearTags()

The method clearTags removes all the tags defined in the compiler.

template.compile(template, options)

The function compile returns a function based of the string template. The argument options will overwrite the default options of the compiler.

The first line of the template can also contains options for the compiler. It must start with '{{}} ' and the options separated with spaces.

{{}} strip:true
hello {{:it.firstname}}
{{}} strip:false varnames:firstname,lastname
hello {{:firstname}}

template.removeTag(name)

The method clearTags removes the tag named name.

template.run(template, variables, options)

The method run will firstly compiles the template with the options and the variables' names. Then it will execute the resulting function with the variables.

console.log(template.run('It\'s nice to meet you, {{:name}}.', {
	name: 'miss White'
}));

This is the least efficient to use a template. Because the template will be compiled every time.

Tags

Interpolation

Interpolation with encoding

Evaluation

Conditionals

Array Iteration

Object Iteration

While Iteration

Do/While Iteration

Range Iteration

Partials

{{:hello()}} { } Hello world! {{#hello(name)}} Hello {{:name}}! {{#}}

{{:hello(it.name)}} { name: 'Jake' } Hello Jake!

Blocks

Comments

Escape

Forked from

Donations

Support this project by becoming a financial contributor.

License

Copyright © 2013-present Baptiste Augrain

Licensed under the MIT license.