Registry / serialization / hogan.js

hogan.js

JSON →
library3.0.2jsnpmunverified

Hogan.js is a Mustache templating compiler developed by Twitter, currently at version 3.0.2. It compiles Mustache templates into reusable HoganTemplate objects with a fast, three-phase process (scanning, parsing, code generation). It supports custom delimiters, template inheritance, pre-compilation, and a parser API for server-side processing. Key differentiators: standalone templates (render without the compiler), lambda features (optional), and compatibility with other Mustache implementations. Release cadence is irregular; latest release is from 2014.

npm install hogan.js
INSTALL
IMPORT
SIG · HOGAN.JS
H
hogan.js
serializationjavascriptv3.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Hogan
✓ import Hogan from 'hogan.js'
✗ const hogan = require('hogan.js');
Default export; CommonJS require also works, but ES module import is preferred in modern codebases.
Hogan.compile()
✓ const template = Hogan.compile('Hello {{name}}!')
✗ const template = new Hogan('Hello {{name}}!')
Hogan is not a constructor; compile is a static method.
HoganTemplate
✓ import { HoganTemplate } from 'hogan.js'
✗ const HoganTemplate = require('hogan.js').HoganTemplate
Named export for the template class; can be used if you have pre-compiled templates.
Hogan.scan() / Hogan.parse()
✓ const tokens = Hogan.scan('{{foo}}'); const tree = Hogan.parse(tokens);
Scan returns an array of tokens, parse returns an AST. Useful for server-side preprocessing.

Demonstrates basic template compilation and rendering using Hogan.js.

// Quickstart: compile and render a template import Hogan from 'hogan.js'; const data = { name: 'World' }; // Compile template string const template = Hogan.compile('Hello {{name}}!'); // Render with data const output = template.render(data); console.log(output); // 'Hello World!' // Pre-compile and render without compiler const precompiled = Hogan.compile('Hello {{name}}!', { asString: true }); // Send precompiled string to client, then: // const HoganTemplate = ... // need Hogan runtime // const template = new HoganTemplate(precompiled); // template.render(data);
Debug
Known issues
gotchaLambda features require the compiler and original template source; pre-compiled templates without the compiler cannot use lambdas.
fix
Ensure the compiler and source are available at render time if using lambdas.
affects: >=3.0.0
deprecatedThe project is no longer actively maintained; last release was in 2014. Security updates are not guaranteed.
fix
Consider migrating to maintained alternatives like Handlebars or mustache.js.
affects: all
gotchaHogan.compile() with { asString: true } returns a string, not a template object; you must later instantiate a HoganTemplate.
fix
Use `new HoganTemplate(compiledString)` after receiving the string.
affects: >=3.0.0
gotchaCustom delimiters must be specified as a string with two delimiters separated by space, e.g., '<% %>'. Incorrect format will be silently ignored.
fix
Check delimiter format; use exactly two tokens separated by a space.
affects: >=3.0.0
Errors
Common errors & fixes
Hogan is not a constructor
Using `new Hogan(...)` instead of `Hogan.compile(...)`. Hogan is an object with static methods, not a constructor.
fix
Replace `new Hogan(template)` with `Hogan.compile(template)`.
Cannot find module 'hogan.js'
Missing npm install or incorrect import path.
fix
Run `npm install hogan.js` and ensure import/require path is correct (e.g., require('hogan.js')).
HoganTemplate is not defined
Trying to use HoganTemplate class without importing it; it is a named export.
fix
Import HoganTemplate from 'hogan.js' or access it as Hogan.HoganTemplate.
Upgrade
Version history
3.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
hogan.js — npm install hogan.js · libregistry