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

gana-compile

v1.0.1

Published

Pretty small synchronous template engine built on ES2015 Template Strings, working on `[email protected]` too. No RegExps, support for helpers and what you want. Use [gana][] if you wanna both async and sync support.

Downloads

17

Readme

gana-compile npmjs.com The MIT License npm downloads

Pretty small synchronous template engine built on ES2015 Template Strings, working on [email protected] too. No RegExps, support for helpers and what you want. Use gana if you wanna both async and sync support.

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

You might also be interested in es6-template (>= v2), which is higher level of gana-compile adding async support, .render and .compile methods.

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-compile. They requires too big codebase - and finally what, they still uses some of the "bad" things in JS.

Biggest names uses "bad" things too

Names such verb, update, templates, generate, assemble in our community uses engine - respectively engine-base and/or engine-cache. 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-compile too.

Tricking magic

Behind the scenes 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 (1.39kb, minified and not gzipped) - 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 standard 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-compile --save

Usage

For more use-cases see the tests

const ganaCompile = require('gana-compile')

ganaCompile

Compiles a template to a function, which accepts locals object to populate the template.

Params

  • template {String}: string to compile to a function
  • returns {Function}: like compileFn(locals), where locals must be object
  • throws {TypeError}: if template not a string
  • throws {TypeError}: if locals not an object
  • throws {ReferenceError}: if key not exists in locals object

Example

var ganaCompile = require('gana-compile')

var template = 'Welcome here, ${ucfirst(name)}! And have fun!'
var locals = {
  name: 'charlike',
  ucfirst: function ucfirst (val) {
    return val.charAt(0).toUpperCase() + val.slice(1)
  }
}

var fn = ganaCompile(template)
var str = fn(locals)

console.log(str)
// => 'Welcome here, Charlike! And have fun!'

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