
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
gana-compile
Advanced tools
Pretty small synchronous template engine built on ES2015 Template Strings, working on `node@0.10` too. No RegExps, support for helpers and what you want. Use [gana][] if you wanna both async and sync support.
Pretty small synchronous template engine built on ES2015 Template Strings, working on
node@0.10too. No RegExps, support for helpers and what you want. Use gana if you wanna both async and sync support.
You might also be interested in es6-template (>= v2), which is higher level of gana-compile adding async support, .render and .compile methods.
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 node@0.10 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.
npm i gana-compile --save
For more use-cases see the tests
const ganaCompile = require('gana-compile')
Compiles a
templateto a function, which acceptslocalsobject to populate the template.
Params
template {String}: string to compile to a functionreturns {Function}: like compileFn(locals), where locals must be objectthrows {TypeError}: if template not a stringthrows {TypeError}: if locals not an objectthrows {ReferenceError}: if key not exists in locals objectExample
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!'
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.
FAQs
Pretty small synchronous template engine built on ES2015 Template Strings, working on `node@0.10` too. No RegExps, support for helpers and what you want. Use [gana][] if you wanna both async and sync support.
We found that gana-compile demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.