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

gana

v1.1.1

Published

Small and powerful template engine with only sync and async compile. The mid-level between [es6-template][] and [gana-compile][].

Readme

gana npmjs.com The MIT License npm downloads

Small and powerful template engine with only sync and async compile. The mid-level between es6-template and gana-compile.

code climate standard code style travis build status coverage status dependency status

You might also be interested:

  • es6-template - higher level than gana and gana-compile, adds .render and .compile methods. (~1.5-2kb)
  • gana-compile - lower level than gana, which does only synchronous compile. (~1.1kb)
  • gana is just ~1.5kb minified, not gzipped.

Background

Uses the "bad" new Function thing

I don't think that's a problem, because other template engines out there also uses some kind of eval and it is used massively, believe. Most of them uses eval, most of them uses with, others of them uses RegExps and etc. They all are with custom non-standard delimiters. They do too much to accomplish same results as gana. They requires too big codebase - and finally what, they still uses some of the "bad" things in JS.
In other side, gana-compile (which is behind this package) uses only new Function and nothing more. The whole core logic thing is just 3-5 lines of code.

Biggest names uses "bad" things, too

Names such verb, update, templates, generate, assemble in our community uses engine / engine-base / engine-cache - engine uses with, new Function and RegExp. Not to mention some of the most famous "real" template engines with features like partials, helpers and etc. You can have partials and helpers here in gana too. The most awesome thing of the engine that is used by verb and assemble is they can have asynchronous helpers - that's awesome, really! But if you will use bad things anyway, the core logic can be done a lot easier, with a lot smaller codebase.

Tricking magic

Behind the scenes gana / gana-compile uses ES2015 (ES6) template strings inside the bad new Function which seems to work even in [email protected] which don't have support for Template Strings! That's strange, but it works and give us that awesome and small codebase without any costs. You just pass normal string 'foo ${bar} and baz' and then { bar: 'bar' } in the returned function.

Note about standard (>= v8) users

Recently in standard was added rule that ban usage of ${} in normal '' strings. So be awere of that and add /* eslint-disable no-template-curly-in-string */ comment before your stuff to get things working without problems.

Install

npm i gana --save

Usage

For more use-cases see the tests

const gana = require('gana')

gana

Sync and async compile, using ${} delimiters and ES2015 Template Strings. Workin' on [email protected] too.

Params

  • <template> {String}: template to compile.
  • [cb] {Function}: optional, function with cb(err, compileFn) signature.
  • returns {Function}: if no cb, returns compileFn that accept object.

Example

var gana = require('gana')

var template = 'Hello, ${ucfirst(author.name)}! Welcome in our ${place}.'
var locals = {
  author: {
    name: 'charlike'
  },
  place: 'club',
  ucfirst: function ucfirst (val) {
    return val.charAt(0).toUpperCase() + val.slice(1)
  }
}

// sync
var compileFn = gana(template)
var result = compileFn(locals)
console.log(result)
// => 'Hello, Charlike! Welcome in our club.'

// asynchronous
gana(template, function callback (err, compileFn) {
  if (err) return console.error(err)

  var result = compileFn(locals)
  console.log(result)
  // => 'Hello, Charlike! Welcome in our club.'
})

Related

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github