techhead-hogan
raw JSON → 0.0.1 verified Fri May 01 auth: no javascript
A fork of Twitter's Hogan.js Mustache compiler (v0.0.1), adding helpers, method call chaining, dot notation, shorthand section close tags, and piped helpers. Released as a pre-1.0 package with limited documentation and bug fixes for delimiter handling and partial context access. Differentiated from Hogan.js by extended functionality for method calls and helpers, but likely incompatible with standard Mustache specifications.
Common errors
error TypeError: hogan.compile is not a function ↓
cause Default import used but package emits a default export object.
fix
Use correct import: import hogan from 'techhead-hogan'; then hogan.compile().
error ReferenceError: require is not defined ↓
cause Attempting CommonJS require in an ESM context.
fix
Use import statement or dynamic import: const hogan = await import('techhead-hogan').then(m => m.default);
error Error: Piped helper 'join' not found ↓
cause Helpers not enabled; enableHelpers option missing.
fix
Compile with { enableHelpers: 1 }.
Warnings
gotcha Helpers require enableHelpers:1 and fixMethodCalls:1 options; otherwise they are ignored. ↓
fix Pass { enableHelpers: 1, fixMethodCalls: 1 } to compile().
gotcha Shorthand close tags (like {/}) depend on delimiter option { delimiters: '{ }' } and may not work with default delimiters. ↓
fix When using shorthand close tags, specify custom delimiters, e.g., { delimiters: '{{ }}' } or '{ }'.
gotcha Method call chaining via dot notation only works when fixMethodCalls option is enabled. ↓
fix Add fixMethodCalls:1 to compile options.
breaking This fork may break compatibility with standard Mustache implementations due to added features. ↓
fix Test templates against standard Mustache spec; avoid using new features if cross-compatibility is required.
Install
npm install techhead-hogan yarn add techhead-hogan pnpm add techhead-hogan Imports
- default wrong
const hogan = require('techhead-hogan')correctimport hogan from 'techhead-hogan' - compile wrong
import { compile } from 'techhead-hogan'; // fails if package uses default export onlycorrectconst { compile } = await import('techhead-hogan'); const t = compile('{{name}}', { delimiters: '{{ }}' }); - render wrong
require('techhead-hogan').compile(...).render(...); // CJS not supportedcorrectconst t = (await import('techhead-hogan')).default.compile('{{name}}'); const output = t.render({ name: 'World' });
Quickstart
import hogan from 'techhead-hogan';
const template = 'Hello {{name}}!';
const compiled = hogan.compile(template);
const output = compiled.render({ name: 'World' });
console.log(output); // Hello World!
// With helpers
const t2 = hogan.compile("{{ names | join }}", { fixMethodCalls: 1, enableHelpers: 1 });
const r2 = t2.render({
names: ['a', 'b'],
join: function(arr) { return arr.join(', '); }
});
console.log(r2); // a, b