# Fumanchu
Handlebars + Helpers Together
Source Index: https://fumanchu.org/llms.txt
## Documentation
### Getting Started
URL: https://fumanchu.org/docs/
Description: Fumanchu Getting Started Guide
# fumanchu
Handlebars + Helpers Together
[](https://github.com/jaredwray/fumanchu/actions/workflows/tests.yaml)
[](https://codecov.io/gh/jaredwray/fumanchu)
[](https://npmjs.com/package/@jaredwray/fumanchu)
[
](https://github.com/jaredwray/fumanchu/blob/main/LICENSE)
[](https://npmjs.com/package/@jaredwray/fumanchu)
[](https://www.jsdelivr.com/package/npm/@jaredwray/fumanchu)
[Handlebars](https://github.com/handlebars-lang/handlebars.js) + [Handlebars-helpers](https://github.com/helpers/handlebars-helpers) (helpers are now maintained in this project) combined into a single package. In addition this project has **drastically** reduced the number of dependencies.
Easily use it as a drop in replacement when using handlebars directly. More than 160 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project. Currently **189 helpers** in **20 categories**! ๐
# Table of Contents
* [Using in Nodejs](#usage-nodejs)
* [Using in the Browser](#usage-in-the-browser)
* [Just using Handlebar Helpers](#using-handlebars-helpers)
* [Migrating from v2 to v3](https://fumanchu.org/docs/migration/v2-to-v3/)
* [Migrating from v3 to v4](https://fumanchu.org/docs/migration/v3-to-v4/)
* [Helpers](https://fumanchu.org/docs/helpers/)
* [array](https://fumanchu.org/docs/helpers/array/)
* [code](https://fumanchu.org/docs/helpers/code/)
* [comparison](https://fumanchu.org/docs/helpers/comparison/)
* [collection](https://fumanchu.org/docs/helpers/collection/)
* [date](https://fumanchu.org/docs/helpers/date/)
* [fs](https://fumanchu.org/docs/helpers/fs/)
* [html](https://fumanchu.org/docs/helpers/html/)
* [i18n](https://fumanchu.org/docs/helpers/i18n/)
* [inflection](https://fumanchu.org/docs/helpers/inflection/)
* [logging](https://fumanchu.org/docs/helpers/logging/)
* [markdown](https://fumanchu.org/docs/helpers/markdown/)
* [match](https://fumanchu.org/docs/helpers/match/)
* [math](https://fumanchu.org/docs/helpers/math/)
* [misc](https://fumanchu.org/docs/helpers/misc/)
* [number](https://fumanchu.org/docs/helpers/number/)
* [object](https://fumanchu.org/docs/helpers/object/)
* [path](https://fumanchu.org/docs/helpers/path/)
* [regex](https://fumanchu.org/docs/helpers/regex/)
* [string](https://fumanchu.org/docs/helpers/string/)
* [url](https://fumanchu.org/docs/helpers/url/)
* [utils](https://fumanchu.org/docs/helpers/utils/)
* [Caching](#caching)
# Usage Nodejs
```bash
npm install @jaredwray/fumanchu --save
```
To use Handlebars with all the helpers:
```javascript
import {fumanchu} from '@jaredwray/fumanchu';
const handlebars = fumanchu(); // this will return handlebars with all the helpers
const template = handlebars.compile('{{#if (eq foo "bar")}}
Foo is bar
{{/if}}');
const html = template({foo: 'bar'});
console.log(html); //
Foo is bar
```
It's just that easy! No need to add Handlebars to your project, it's already included.
# Usage in the Browser
Fumanchu ships a browser-safe build that excludes Node-only helpers (`fs`, `path`, `logging`, `embed`, `css`, `js`, `escape`, `urlResolve`, `urlParse`, `stripProtocol`). Import it directly via the `/browser` subpath:
```javascript
import { fumanchu } from '@jaredwray/fumanchu/browser';
const handlebars = fumanchu();
const template = handlebars.compile('{{uppercase name}}');
console.log(template({ name: 'hello' })); // HELLO
```
The package also sets the `browser` export condition on the main entry, so webpack, Vite, esbuild, Rollup, and other browser-aware bundlers automatically pick up the browser build when you `import '@jaredwray/fumanchu'` from a browser target โ no code change required. The public API (`fumanchu`, `helpers`, `HelperRegistry`) is identical to Node; only the set of registered helpers differs.
You can also load the browser build directly from a CDN such as [jsDelivr](https://www.jsdelivr.com/package/npm/@jaredwray/fumanchu) โ no bundler required:
```html
```
# Using Handlebars Helpers
If you only want to use handlebar helpers you can easily do that by doing the following:
```javascript
import {helpers} from '@jaredwray/fumanchu';
import handlebars from 'handlebars';
const helpersFunction = await helpers();
helpersFunction({ handlebars: handlebars });
const template = handlebars.compile('{{#if (eq foo "bar")}}
Foo is bar
{{/if}}');
const html = template({foo: 'bar'});
console.log(html); //
Foo is bar
```
If using it with es6 you can access `handlebars` and `helpers`:
```javascript
import {handlebars, helpers} from '@jaredwray/fumanchu';
helpers({ handlebars: handlebars });
const template = handlebars.compile('{{#if (eq foo "bar")}}
Foo is bar
{{/if}}');
const html = template({foo: 'bar'});
console.log(html);
```
# Using the Helper Registry
The helper registry allows you to manage and use Handlebars helpers more easily. You can register new helpers, filter existing ones, and access them in your templates.
```js
import { HelperRegistry, handlebars } from '@jaredwray/fumanchu';
const registry = new HelperRegistry();
registry.register('eq', (a, b) => a === b);
registry.register('if', (condition, template) => condition ? template() : '');
const hbs = handlebars;
registry.load(hbs); // Load all helpers into Handlebars
```
If you want to do filtering you can use the `HelperFilter` on `load`:
```js
import { HelperRegistry, handlebars } from '@jaredwray/fumanchu';
const registry = new HelperRegistry();
registry.register('eq', (a, b) => a === b);
registry.register('if', (condition, template) => condition ? template() : '');
const hbs = handlebars;
registry.load(hbs, { names: ['if']}); // Load the helpers into Handlebars
```
In addition, we have made the helper functions have a compatibility such as `HelperRegistryCompatibility.NODEJS` or `HelperRegistryCompatibility.BROWSER`. This will allow you to filter out based on your environment!
# Caching
When caching is enabled, Fumanchu wraps the Handlebars `compile()` method to cache compiled template functions using [@cacheable/memory](https://github.com/jaredwray/cacheable/tree/main/packages/memory). If you compile the same template string multiple times, the cached version is returned instead of recompiling. The returned Handlebars instance is fully compatible -- caching is transparent to your existing code.
The `caching` option accepts three types:
- `boolean` -- `true` enables caching with defaults, `false` disables it
- `CacheableMemory` -- a pre-configured instance from `@cacheable/memory`
- `CacheableMemoryOptions` -- an options object passed to `CacheableMemory` (supports `ttl`, `lruSize`, `checkInterval`, etc.)
Here is an quick benchmark showing the performance advantage:
| name | summary | ops/sec | time/op | margin | samples |
|------------------------------------|:---------:|----------:|----------:|:--------:|----------:|
| compile+render cached (v4.6.0) | ๐ฅ | 45K | 39ยตs | ยฑ0.32% | 25K |
| compile+render no-cache (v4.6.0) | -83% | 8K | 166ยตs | ยฑ0.62% | 10K |
## Enable caching with default settings
```javascript
import { fumanchu } from '@jaredwray/fumanchu';
const handlebars = fumanchu({ caching: true });
const template = handlebars.compile('Hello {{name}}!');
template({ name: 'World' }); // compiles and caches
const template2 = handlebars.compile('Hello {{name}}!');
// returns the cached compiled function -- no recompilation
```
## Pass caching options
```javascript
import { fumanchu } from '@jaredwray/fumanchu';
const handlebars = fumanchu({
caching: {
ttl: '1h', // Time-to-live in ms or human-readable string like '1h'
lruSize: 500, // LRU cache size limit (0 = unlimited)
checkInterval: 0, // Interval to check for expired items in ms (0 = disabled)
},
});
```
## Pass a pre-configured `CacheableMemory` instance
This is useful if you want to share a cache across multiple Fumanchu instances or manage the cache lifecycle yourself:
```javascript
import { fumanchu, CacheableMemory } from '@jaredwray/fumanchu';
const cache = new CacheableMemory({ ttl: '1h', lruSize: 1000, useClone: false });
const hbs1 = fumanchu({ caching: cache });
const hbs2 = fumanchu({ caching: cache }); // shares the same cache as hbs1
```
### Array Helpers
URL: https://fumanchu.org/docs/helpers/array/
Description: Fumanchu provides a set of built-in helpers for working with arrays. These helpers allow you to iterate over arrays, check their length, and perform other common operations.
> **Availability:** Registered in both the Node and browser builds.
### {{after}}
Returns all of the items in an array after the specified index. Opposite of [before](#before).
**Params**
* `array` **{Array}**: Collection
* `n` **{Number}**: Starting index (number of items to exclude)
* `returns` **{Array}**: Array exluding `n` items.
**Example**
```html
{{after array 1}}
```
### {{arrayify}}
Cast the given `value` to an array.
**Params**
* `value` **{any}**
* `returns` **{Array}**
**Example**
```html
{{arrayify "foo"}}
```
### {{before}}
Return all of the items in the collection before the specified count. Opposite of [after](#after).
**Params**
* `array` **{Array}**
* `n` **{Number}**
* `returns` **{Array}**: Array excluding items after the given number.
**Example**
```html
{{before array 2}}
```
### {{eachIndex}}
**Params**
* `array` **{Array}**
* `options` **{Object}**
* `returns` **{String}**
**Example**
```html
{{#eachIndex array}}
{{item}} is {{index}}
{{/eachIndex}}
```
### {{filter}}
Block helper that filters the given array and renders the block for values that evaluate to `true`, otherwise the inverse block is returned.
**Params**
* `array` **{Array}**
* `value` **{any}**
* `options` **{Object}**
* `returns` **{String}**
**Example**
```html
{{#filter array "foo"}}AAA{{else}}BBB{{/filter}}
```
### {{first}}
Returns the first item, or first `n` items of an array.
**Params**
* `array` **{Array}**
* `n` **{Number}**: Number of items to return, starting at `0`.
* `returns` **{Array}**
**Example**
```html
{{first "['a', 'b', 'c', 'd', 'e']" 2}}
```
### {{forEach}}
Iterates over each item in an array and exposes the current item in the array as context to the inner block. In addition to the current array item, the helper exposes the following variables to the inner block:
* `index`
* `total`
* `isFirst`
* `isLast`
Also, `@index` is exposed as a private variable, and additional
private variables may be defined as hash arguments.
**Params**
* `array` **{Array}**
* `returns` **{String}**
**Example**
```html
{{#forEach accounts}}
{{ name }}
{{#unless isLast}}, {{/unless}}
{{/forEach}}
```
### {{inArray}}
Block helper that renders the block if an array has the given `value`. Optionally specify an inverse block to render when the array does not have the given value.
**Params**
* `array` **{Array}**
* `value` **{any}**
* `options` **{Object}**
* `returns` **{String}**
**Example**
```html
{{#inArray array "d"}}
foo
{{else}}
bar
{{/inArray}}
```
### {{isArray}}
Returns true if `value` is an es5 array.
**Params**
* `value` **{any}**: The value to test.
* `returns` **{Boolean}**
**Example**
```html
{{isArray "abc"}}
{{isArray array}}
```
### {{itemAt}}
Returns the item from `array` at index `idx`.
**Params**
* `array` **{Array}**
* `idx` **{Number}**
* `returns` **{any}** `value`
**Example**
```html
{{itemAt array 1}}
```
### {{join}}
Join all elements of array into a string, optionally using a given separator.
**Params**
* `array` **{Array}**
* `separator` **{String}**: The separator to use. Defaults to `,`.
* `returns` **{String}**
**Example**
```html
{{join array}}
{{join array '-'}}
```
### {{equalsLength}}
Returns true if the the length of the given `value` is equal
to the given `length`. Can be used as a block or inline helper.
**Params**
* `value` **{Array|String}**
* `length` **{Number}**
* `options` **{Object}**
* `returns` **{String}**
### {{last}}
Returns the last item, or last `n` items of an array or string. Opposite of [first](#first).
**Params**
* `value` **{Array|String}**: Array or string.
* `n` **{Number}**: Number of items to return from the end of the array.
* `returns` **{Array}**
**Example**
```html
{{last value}}
{{last value 2}}
{{last value 3}}
```
### {{length}}
Returns the length of the given string or array.
**Params**
* `value` **{Array|Object|String}**
* `returns` **{Number}**: The length of the value.
**Example**
```html
{{length '["a", "b", "c"]'}}
{{length myArray}}
{{length myObject}}
```
### {{lengthEqual}}
Alias for [equalsLength](#equalsLength)
### {{map}}
Returns a new array, created by calling `function` on each element of the given `array`. For example,
**Params**
* `array` **{Array}**
* `fn` **{Function}**
* `returns` **{String}**
**Example**
```html
{{map array double}}
```
### {{pluck}}
Map over the given object or array or objects and create an array of values from the given `prop`. Dot-notation may be used (as a string) to get nested properties.
**Params**
* `collection` **{Array|Object}**
* `prop` **{Function}**
* `returns` **{String}**
**Example**
```html
// {{pluck items "data.title"}}
```
### {{reverse}}
Reverse the elements in an array, or the characters in a string.
**Params**
* `value` **{Array|String}**
* `returns` **{Array|String}**: Returns the reversed string or array.
**Example**
```html
{{reverse value}}
{{reverse value}}
```
### {{some}}
Block helper that returns the block if the callback returns true for some value in the given array.
**Params**
* `array` **{Array}**
* `iter` **{Function}**: Iteratee
* **{Options}**: Handlebars provided options object
* `returns` **{String}**
**Example**
```html
{{#some array isString}}
Render me if the array has a string.
{{else}}
Render me if it doesn't.
{{/some}}
```
### {{sort}}
Sort the given `array`. If an array of objects is passed, you may optionally pass a `key` to sort on as the second argument. You may alternatively pass a sorting function as the second argument.
**Params**
* `array` **{Array}**: the array to sort.
* `key` **{String|Function}**: The object key to sort by, or sorting function.
**Example**
```html
{{sort array}}
```
### {{sortBy}}
Sort an `array`. If an array of objects is passed, you may optionally pass a `key` to sort on as the second argument. You may alternatively pass a sorting function as the second argument.
**Params**
* `array` **{Array}**: the array to sort.
* `props` **{String|Function}**: One or more properties to sort by, or sorting functions to use.
**Example**
```html
{{sortBy array "a"}}
```
### {{withAfter}}
Use the items in the array _after_ the specified index as context inside a block. Opposite of [withBefore](#withBefore).
**Params**
* `array` **{Array}**
* `idx` **{Number}**
* `options` **{Object}**
* `returns` **{Array}**
**Example**
```html
{{#withAfter array 3}}
{{this}}
{{/withAfter}}
```
### {{withBefore}}
Use the items in the array _before_ the specified index as context inside a block. Opposite of [withAfter](#withAfter).
**Params**
* `array` **{Array}**
* `idx` **{Number}**
* `options` **{Object}**
* `returns` **{Array}**
**Example**
```html
{{#withBefore array 3}}
{{this}}
{{/withBefore}}
```
### {{withFirst}}
Use the first item in a collection inside a handlebars block expression. Opposite of [withLast](#withLast).
**Params**
* `array` **{Array}**
* `idx` **{Number}**
* `options` **{Object}**
* `returns` **{String}**
**Example**
```html
{{#withFirst array}}
{{this}}
{{/withFirst}}
```
### {{withGroup}}
Block helper that groups array elements by given group `size`.
**Params**
* `array` **{Array}**: The array to iterate over
* `size` **{Number}**: The desired length of each array "group"
* `options` **{Object}**: Handlebars options
* `returns` **{String}**
**Example**
```html
{{#withGroup array 4}}
{{#each this}}
{{.}}
{{each}}
{{/withGroup}}
```
### {{withLast}}
Use the last item or `n` items in an array as context inside a block. Opposite of [withFirst](#withFirst).
**Params**
* `array` **{Array}**
* `idx` **{Number}**: The starting index.
* `options` **{Object}**
* `returns` **{String}**
**Example**
```html
{{#withLast array}}
{{this}}
{{/withLast}}
```
### {{withSort}}
Block helper that sorts a collection and exposes the sorted collection as context inside the block.
**Params**
* `array` **{Array}**
* `prop` **{String}**
* `options` **{Object}**: Specify `reverse="true"` to reverse the array.
* `returns` **{String}**
**Example**
```html
{{#withSort array}}{{this}}{{/withSort}}
```
### {{unique}}
Block helper that return an array with all duplicate values removed. Best used along with a [each](#each) helper.
**Params**
* `array` **{Array}**
* `options` **{Object}**
* `returns` **{Array}**
**Example**
```html
{{#each (unique array)}}{{.}}{{/each}}
```
### Logging Helpers
URL: https://fumanchu.org/docs/helpers/logging/
Description: Handlebars provides a set of built-in helpers for logging and debugging. These helpers output messages to the terminal with various formatting and color options, making it easier to debug templates and display status information. Node.js only.
> **Availability:** Registered in the Node build only. Not available in the browser build.
## logging
> **Note:** These helpers are only available in Node.js environments. They are not compatible with browser-based Handlebars usage.
These helpers output messages to the terminal with ANSI color formatting. All logging helpers return an empty string to avoid affecting template output.
### {{log}}
Logs an unstyled message to the terminal via `console.log`.
**Params**
* `...args` **{any}**: Values to log
* `returns` **{String}**: Empty string
**Example**
```html
{{log "Processing item:" itemName}}
```
### {{ok}}
Logs a green colored message preceded by a checkmark to the terminal. Useful for indicating successful operations.
**Params**
* `...args` **{any}**: Values to log (will be joined with spaces)
* `returns` **{String}**: Empty string
**Example**
```html
{{ok "Build completed successfully"}}
```
### {{success}}
Logs a green colored message to the terminal. Similar to `ok` but without the checkmark.
**Params**
* `...args` **{any}**: Values to log (will be joined with spaces)
* `returns` **{String}**: Empty string
**Example**
```html
{{success "All tests passed"}}
```
### {{info}}
Logs a cyan colored informational message to the terminal.
**Params**
* `...args` **{any}**: Values to log (will be joined with spaces)
* `returns` **{String}**: Empty string
**Example**
```html
{{info "Processing" totalCount "items"}}
```
### {{warning}}
Logs a yellow colored warning message to stderr.
**Params**
* `...args` **{any}**: Values to log (will be joined with spaces)
* `returns` **{String}**: Empty string
**Example**
```html
{{warning "Deprecated feature detected"}}
```
### {{warn}}
Alias for `{{warning}}`. Logs a yellow colored warning message to stderr.
**Params**
* `...args` **{any}**: Values to log (will be joined with spaces)
* `returns` **{String}**: Empty string
**Example**
```html
{{warn "This method will be removed in v5"}}
```
### {{error}}
Logs a red colored error message to stderr.
**Params**
* `...args` **{any}**: Values to log (will be joined with spaces)
* `returns` **{String}**: Empty string
**Example**
```html
{{error "Failed to process item:" itemId}}
```
### {{danger}}
Alias for `{{error}}`. Logs a red colored error message to stderr.
**Params**
* `...args` **{any}**: Values to log (will be joined with spaces)
* `returns` **{String}**: Empty string
**Example**
```html
{{danger "Critical failure in module"}}
```
### {{bold}}
Logs a bold formatted message to stderr.
**Params**
* `...args` **{any}**: Values to log (will be joined with spaces)
* `returns` **{String}**: Empty string
**Example**
```html
{{bold "Important Notice"}}
```
### {{_debug}}
Outputs debug information including the provided value and the current Handlebars context. Useful for inspecting template data during development.
**Params**
* `...args` **{any}**: Optional values to inspect
* `returns` **{String}**: Empty string
**Example**
```html
{{_debug user}}
```
### {{_inspect}}
Formats a value as JSON and returns it for display in the template. Supports different output formats.
**Params**
* `context` **{any}**: The value to inspect
* `options.hash.type` **{String}**: Output format: `"html"` (default), `"md"`, or any other value for raw JSON
* `returns` **{String}**: Formatted JSON string
**Example**
```html
{{_inspect user}}
{{_inspect user type="md"}}
{{_inspect user type="raw"}}
```
### Code Helpers
URL: https://fumanchu.org/docs/helpers/code/
Description: Handlebars provides a set of built-in helpers for working with code. These helpers are used to format and manipulate code snippets, making it easier to display code in a readable format.
> **Availability**
>
> | Helper | Node | Browser |
> | --- | :---: | :---: |
> | `embed` | โ | โ |
> | `gist` | โ | โ |
> | `jsfiddle` | โ | โ |
# Code Helpers
### {{embed}}
Embed code from an external file as preformatted text.
**Params**
* `filepath` **{String}**: filepath to the file to embed.
* `language` **{String}**: Optionally specify the language to use for syntax highlighting.
* `returns` **{String}**
**Example**
```html
{{embed 'path/to/file.js'}}
{{embed 'path/to/file.hbs' 'html'}}
```
### {{gist}}
Embed a GitHub Gist using only the id of the Gist
**Params**
* `id` **{String}**
* `returns` **{String}**
**Example**
```html
{{gist "12345"}}
```
### {{jsfiddle}}
Generate the HTML for a jsFiddle iframe with the given options.
**Params**
* `id` **{String}**: The jsFiddle id (required)
* `width` **{String}**: Width of the iframe (default: "100%")
* `height` **{String}**: Height of the iframe (default: "300")
* `skin` **{String}**: Skin path (default: "/presentation/")
* `tabs` **{String}**: Tabs to display (default: "result,js,html,css")
* `allowfullscreen` **{String}**: Allowfullscreen attribute (default: "allowfullscreen")
* `frameborder` **{String}**: Frameborder attribute (default: "0")
* `returns` **{String}**
**Example**
```html
{{jsfiddle id="0dfk10ks"}}
{{jsfiddle id="0dfk10ks" height="500" tabs="js,result"}}
```
### Comparison Helpers
URL: https://fumanchu.org/docs/helpers/comparison/
Description: Handlebars provides a set of built-in helpers for performing comparisons. These helpers are used to compare values, making it easier to implement conditional logic in your templates.
> **Availability:** Registered in both the Node and browser builds.
## comparison
### {{and}}
Helper that renders the block if **all** of the given values are truthy. If an inverse block is specified it will be rendered when falsy. Works as a block helper, inline helper or subexpression.
**Params**
* `values` **{any}**: Variable number of values to check
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (and great magnificent)}}A{{else}}B{{/if}}
{{#if (and great magnificent)}}A{{else}}B{{/if}}
```
### {{compare}}
Render a block when a comparison of the first and third arguments returns true. The second argument is the operator to use.
**Supported Operators**
* `==` - loose equality
* `===` - strict equality
* `!=` - loose inequality
* `!==` - strict inequality
* `<` - less than
* `>` - greater than
* `<=` - less than or equal
* `>=` - greater than or equal
* `typeof` - checks if typeof first argument equals second argument
**Params**
* `a` **{any}**: The first value to compare
* `operator` **{String}**: The operator to use for comparison
* `b` **{any}**: The second value to compare
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (compare 10 ">" 5)}}A{{else}}B{{/if}}
{{#if (compare "hello" "typeof" "string")}}A{{else}}B{{/if}}
```
### {{contains}}
Block helper that renders the block if `collection` has the given `value`, otherwise the inverse block is rendered (if specified). If a `startIndex` is specified, the search begins at that index.
**Params**
* `collection` **{Array|Object|String}**: The collection to search.
* `value` **{any}**: The value to check for.
* `[startIndex=0]` **{Number}**: Optionally define the starting index.
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (contains array "b")}}
This will be rendered.
{{else}}
This will not be rendered.
{{/if}}
{{#if (contains "hello world" "world")}}
Found it!
{{/if}}
{{#if (contains object "keyName")}}
Key exists!
{{/if}}
```
### {{default}}
Returns the first value that is not null or undefined, otherwise returns an empty string.
**Params**
* `values` **{any}**: Variable number of values to check
* `returns` **{any}**: The first non-null/undefined value, or empty string
**Example**
```handlebars
{{default title "Untitled"}}
{{default a b c "fallback"}}
```
### {{eq}}
Block helper that renders a block if `a` is **strictly equal to** `b` (using `===`).
If an inverse block is specified it will be rendered when falsy.
**Params**
* `a` **{any}**
* `b` **{any}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (eq name "John")}}
Hello John!
{{else}}
Hello stranger!
{{/if}}
```
### {{gt}}
Block helper that renders a block if `a` is **greater than** `b`.
**Params**
* `a` **{any}**
* `b` **{any}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (gt count 10)}}
More than 10 items
{{else}}
10 or fewer items
{{/if}}
```
### {{gte}}
Block helper that renders a block if `a` is **greater than or equal to** `b`.
**Params**
* `a` **{any}**
* `b` **{any}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (gte age 18)}}
Adult
{{else}}
Minor
{{/if}}
```
### {{has}}
Block helper that renders a block if `value` has `pattern`.
If an inverse block is specified it will be rendered when falsy.
**Params**
* `value` **{any}**: The value to check (array, string, or object).
* `pattern` **{any}**: The pattern to check for.
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (has array "b")}}
Found it!
{{/if}}
{{#if (has "hello world" "world")}}
Found it!
{{/if}}
{{#if (has user "email")}}
User has email
{{/if}}
```
### {{isFalsey}}
Returns true if the given `value` is falsey. Recognizes common falsey keywords like "false", "no", "none", "null", "0", "nope", etc.
**Params**
* `val` **{any}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (isFalsey value)}}
Value is falsey
{{/if}}
{{#if (isFalsey "no")}}
This renders because "no" is falsey
{{/if}}
```
### {{isTruthy}}
Returns true if the given `value` is truthy (not falsey).
**Params**
* `val` **{any}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (isTruthy value)}}
Value is truthy
{{/if}}
```
### {{ifEven}}
Returns true if the given value is an even number.
**Params**
* `number` **{Number}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (ifEven value)}}
Value is even
{{else}}
Value is odd
{{/if}}
```
### {{ifNth}}
Returns true if `b` is divisible by `a` (remainder is zero when `b` is divided by `a`).
**Params**
* `a` **{Number}**: The divisor
* `b` **{Number}**: The number to check
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (ifNth 3 index)}}
Index is divisible by 3
{{/if}}
```
### {{ifOdd}}
Block helper that renders a block if `value` is **an odd number**.
**Params**
* `value` **{Number}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (ifOdd value)}}
Value is odd
{{else}}
Value is even
{{/if}}
```
### {{is}}
Block helper that renders a block if `a` is **equal to** `b` using loose equality (`==`).
Similar to [eq](#eq) but does not use strict equality.
**Params**
* `a` **{any}**
* `b` **{any}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (is 1 "1")}}
This renders because 1 == "1" is true
{{/if}}
```
### {{isnt}}
Block helper that renders a block if `a` is **not equal to** `b` using loose inequality (`!=`).
Similar to [unlessEq](#unlesseq) but does not use strict equality.
**Params**
* `a` **{any}**
* `b` **{any}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (isnt name "admin")}}
Not admin
{{/if}}
```
### {{lt}}
Block helper that renders a block if `a` is **less than** `b`.
**Params**
* `a` **{any}**
* `b` **{any}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (lt age 18)}}
Minor
{{else}}
Adult
{{/if}}
```
### {{lte}}
Block helper that renders a block if `a` is **less than or equal to** `b`.
**Params**
* `a` **{any}**
* `b` **{any}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (lte count 10)}}
10 or fewer items
{{else}}
More than 10 items
{{/if}}
```
### {{neither}}
Block helper that renders a block if **neither of** the given values are truthy.
**Params**
* `a` **{any}**
* `b` **{any}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (neither isAdmin isModerator)}}
Regular user
{{else}}
Has elevated privileges
{{/if}}
```
### {{not}}
Returns true if `val` is falsey. Works as a block or inline helper.
**Params**
* `val` **{any}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (not isLoggedIn)}}
Please log in
{{/if}}
```
### {{or}}
Block helper that renders a block if **any of** the given values is truthy.
**Params**
* `values` **{any}**: Variable number of values to check
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (or isAdmin isModerator isOwner)}}
Has access
{{else}}
Access denied
{{/if}}
```
### {{unlessEq}}
Block helper that returns true **unless `a` is strictly equal to `b`** (using `!==`).
**Params**
* `a` **{any}**
* `b` **{any}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (unlessEq status "active")}}
Status is not active
{{/if}}
```
### {{unlessGt}}
Block helper that returns true **unless `a` is greater than `b`** (equivalent to `a <= b`).
**Params**
* `a` **{any}**
* `b` **{any}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (unlessGt count 100)}}
Count is 100 or less
{{/if}}
```
### {{unlessLt}}
Block helper that returns true **unless `a` is less than `b`** (equivalent to `a >= b`).
**Params**
* `a` **{any}**
* `b` **{any}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (unlessLt age 18)}}
18 or older
{{/if}}
```
### {{unlessGteq}}
Block helper that returns true **unless `a` is greater than or equal to `b`** (equivalent to `a < b`).
**Params**
* `a` **{any}**
* `b` **{any}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (unlessGteq age 21)}}
Under 21
{{/if}}
```
### {{unlessLteq}}
Block helper that returns true **unless `a` is less than or equal to `b`** (equivalent to `a > b`).
**Params**
* `a` **{any}**
* `b` **{any}**
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (unlessLteq count 0)}}
Count is greater than 0
{{/if}}
```
### Collection Helpers
URL: https://fumanchu.org/docs/helpers/collection/
Description: Handlebars provides a set of built-in helpers for working with collections. These helpers are used to manipulate and format collections, making it easier to work with data in templates.
> **Availability:** Registered in both the Node and browser builds.
## collection
### {{isEmpty}}
Inline, subexpression, or block helper that returns true (or the block) if the given collection is empty, or false (or the inverse block, if supplied) if the collection is not empty.
A collection is considered empty if:
- It is `null` or `undefined`
- It is an array with length 0
- It is an object with no keys
**Params**
* `collection` **{Array|Object}**: The collection to check
* `returns` **{Boolean}**
**Example**
```handlebars
{{#if (isEmpty array)}}
Array is empty
{{else}}
Array has items
{{/if}}
{{#if (isEmpty object)}}
Object is empty
{{/if}}
{{#if (isEmpty array)}}
Empty
{{else}}
Has {{array.length}} items
{{/if}}
```
### {{iterate}}
Block helper that iterates over an array or object. If an array is given, it iterates over each element with its index. If an object is given, it iterates over each key-value pair. If the collection is null/undefined or not iterable, the inverse block is returned.
**Params**
* `collection` **{Object|Array}**: The collection to iterate over
* `fn` **{Function}**: The block function called for each item, receives `(value, key/index)`
* `inverse` **{Function}**: Optional inverse block if collection is empty or invalid
* `returns` **{String}**
**Example**
```handlebars
{{#iterate array}}
Index {{@index}}: {{this}}
{{/iterate}}
{{#iterate object}}
{{@key}}: {{this}}
{{/iterate}}
{{#iterate emptyArray}}
{{this}}
{{else}}
No items found
{{/iterate}}
```
### Date Helpers
URL: https://fumanchu.org/docs/helpers/date/
Description: Handlebars provides a comprehensive set of built-in helpers for working with dates. These helpers are used to format, manipulate, and compare dates, making it easier to display and work with date information.
> **Availability:** Registered in both the Node and browser builds.
## Date Helpers
Fumanchu provides powerful date manipulation capabilities using dayjs and chrono-node for natural language date parsing.
### {{year}}
Get the current year as a string.
**Example**
```handlebars
{{year}}
```
### {{date}}
Format a date with support for human-readable date strings, Date objects, timestamps, or defaults to current date.
**Parameters:**
- `dateInput` (optional): Date string, Date object, timestamp, or undefined (defaults to now)
- `format` (optional): Format string (defaults to "YYYY-MM-DD")
**Supported format tokens:**
- `YYYY` or `yyyy`: 4-digit year
- `YY` or `yy`: 2-digit year
- `MM` or `mm`: Month (01-12)
- `DD` or `dd`: Day of month (01-31)
- `HH` or `hh`: Hour (00-23)
- `mm`: Minute (00-59)
- `ss`: Second (00-59)
**Examples**
```handlebars
{{date "January 15, 2023" "YYYY-MM-DD"}}
{{date "5 years ago" "YYYY"}}
{{date "next Friday" "MM/DD/YYYY"}}
{{date}}
{{date "2023-01-15" "dd/mm/yyyy"}}
```
### {{moment}}
Legacy alias for `{{date}}`. Works exactly the same as the date helper.
**Example**
```handlebars
{{moment "December 25, 2023" "YYYY-MM-DD"}}
```
---
## Current Time Helpers
### {{timestamp}}
Returns the current Unix timestamp in milliseconds.
**Example**
```handlebars
{{timestamp}}
```
### {{now}}
Returns the current date/time with optional formatting.
**Parameters:**
- `format` (optional): Format string (defaults to "YYYY-MM-DD HH:mm:ss")
**Examples**
```handlebars
{{now}}
{{now "YYYY-MM-DD"}}
{{now "HH:mm:ss"}}
```
---
## Relative Time Helpers
### {{fromNow}}
Display relative time from now (e.g., "5 minutes ago", "in 2 hours").
**Parameters:**
- `dateInput`: Date string, Date object, or timestamp
**Examples**
```handlebars
{{fromNow "2 days ago"}}
{{fromNow "tomorrow"}}
{{fromNow "January 1, 2025"}}
```
### {{ago}}
Alias for `{{fromNow}}`. Shows how long ago a date was.
**Example**
```handlebars
{{ago "5 minutes ago"}}
```
### {{toNow}}
Opposite of `fromNow`. Shows relative time to now (less commonly used).
**Example**
```handlebars
{{toNow "2 hours ago"}}
```
---
## Date Arithmetic Helpers
### {{dateAdd}}
Add time to a date.
**Parameters:**
- `dateInput` (optional): Date to add to (defaults to now)
- `amount`: Number to add
- `unit`: Unit of time ("year", "month", "week", "day", "hour", "minute", "second")
**Examples**
```handlebars
{{dateAdd "2023-01-15" 5 "days"}}
{{dateAdd "2023-01-15" 2 "months"}}
{{dateAdd undefined 1 "year"}}
```
### {{dateSubtract}}
Subtract time from a date.
**Parameters:**
- `dateInput` (optional): Date to subtract from (defaults to now)
- `amount`: Number to subtract
- `unit`: Unit of time
**Examples**
```handlebars
{{dateSubtract "2023-01-15" 5 "days"}}
{{dateSubtract "2023-01-15" 2 "weeks"}}
```
---
## Date Period Helpers
### {{startOf}}
Get the start of a time period.
**Parameters:**
- `dateInput` (optional): Date (defaults to now)
- `unit`: Unit of time ("year", "month", "week", "day", "hour", "minute", "second")
**Examples**
```handlebars
{{startOf "2023-01-15" "month"}}
{{startOf "2023-06-15" "year"}}
{{startOf "2023-01-15 14:30:45" "day"}}
```
### {{endOf}}
Get the end of a time period.
**Parameters:**
- `dateInput` (optional): Date (defaults to now)
- `unit`: Unit of time
**Examples**
```handlebars
{{endOf "2023-01-15" "month"}}
{{endOf "2023-06-15" "year"}}
```
---
## Date Comparison Helpers
### {{isBefore}}
Check if the first date is before the second date.
**Parameters:**
- `date1`: First date
- `date2`: Second date
**Returns:** `true` or `false`
**Example**
```handlebars
{{#if (isBefore "2023-01-10" "2023-01-15")}}
Date 1 is before Date 2
{{/if}}
```
### {{isAfter}}
Check if the first date is after the second date.
**Parameters:**
- `date1`: First date
- `date2`: Second date
**Returns:** `true` or `false`
**Example**
```handlebars
{{#if (isAfter "2023-01-20" "2023-01-15")}}
Date 1 is after Date 2
{{/if}}
```
### {{isSame}}
Check if two dates are the same, with optional unit precision.
**Parameters:**
- `date1`: First date
- `date2`: Second date
- `unit` (optional): Unit for comparison ("year", "month", "day", etc.)
**Returns:** `true` or `false`
**Examples**
```handlebars
{{#if (isSame "2023-01-15" "2023-01-15")}}
Dates are the same
{{/if}}
{{#if (isSame "2023-01-15" "2023-12-31" "year")}}
Same year
{{/if}}
```
### {{isBetween}}
Check if a date is between two other dates (inclusive).
**Parameters:**
- `dateInput`: Date to check
- `startDate`: Start of range
- `endDate`: End of range
**Returns:** `true` or `false`
**Example**
```handlebars
{{#if (isBetween "2023-01-15" "2023-01-10" "2023-01-20")}}
Date is in range
{{/if}}
```
---
## Date Utilities
### {{diff}}
Calculate the difference between two dates.
**Parameters:**
- `date1`: First date
- `date2`: Second date
- `unit` (optional): Unit for result ("year", "month", "day", "hour", etc.). Defaults to milliseconds.
**Returns:** Number
**Examples**
```handlebars
{{diff "2023-01-20" "2023-01-15" "days"}}
{{diff "2023-03-15" "2023-01-15" "months"}}
{{diff "2025-01-15" "2023-01-15" "years"}}
```
### {{toISOString}}
Convert a date to ISO 8601 format.
**Parameters:**
- `dateInput`: Date to convert
**Examples**
```handlebars
{{toISOString "2023-01-15"}}
{{toISOString "January 15, 2023"}}
```
---
## Internationalization Helpers
### {{dateTimezone}}
Format a date in a specific timezone.
**Parameters:**
- `dateInput`: Date to format
- `timezone`: IANA timezone string (e.g., "America/New_York", "UTC", "Europe/London")
- `format` (optional): Format string (defaults to "YYYY-MM-DD HH:mm:ss")
**Examples**
```handlebars
{{dateTimezone "2023-01-15 12:00:00" "America/New_York" "YYYY-MM-DD HH:mm:ss"}}
{{dateTimezone "2023-01-15" "UTC"}}
```
### {{dateLocale}}
Format a date with a specific locale.
**Parameters:**
- `dateInput`: Date to format
- `locale`: Locale code (e.g., "en", "fr", "de")
- `format` (optional): Format string (defaults to "YYYY-MM-DD HH:mm:ss")
**Example**
```handlebars
{{dateLocale "2023-01-15" "en" "YYYY-MM-DD"}}
```
---
## Natural Language Date Parsing
All date helpers support natural language date parsing powered by chrono-node:
- "today", "tomorrow", "yesterday"
- "next Friday", "last Monday"
- "5 days ago", "in 2 weeks"
- "January 15, 2023"
- "2023-01-15"
- Date objects
- Unix timestamps
**Examples**
```handlebars
{{date "tomorrow" "YYYY-MM-DD"}}
{{date "next Friday" "MM/DD/YYYY"}}
{{date "5 years ago" "YYYY"}}
{{fromNow "2 hours ago"}}
{{dateAdd "next week" 3 "days"}}
```
### File System Helpers
URL: https://fumanchu.org/docs/helpers/fs/
Description: Handlebars provides a set of built-in helpers for working with the file system. These helpers are used to read and manipulate files, making it easier to work with file data in templates.
> **Availability:** Registered in the Node build only. Not available in the browser build.
## fs
### {{fileSize}}
Formats a number of bytes into a human-readable file size string with appropriate units.
**Params**
* `value` **{Number|Object}**: The number of bytes, or an object with a `length` property
* `precision` **{Number}**: Optional decimal precision (default: 2)
* `returns` **{String}**: Formatted file size string
**Supported Units**
B, kB, MB, GB, TB, PB, EB, ZB, YB
**Example**
```handlebars
{{fileSize 1024}}
{{fileSize 1536}}
{{fileSize 1048576}}
{{fileSize 1073741824}}
{{fileSize 1536 0}}
{{fileSize 1536 3}}
{{fileSize null}}
```
### {{read}}
Read a file from the file system. This is useful in composing "include"-style helpers using sub-expressions.
**Params**
* `filepath` **{String}**: The path to the file to read
* `returns` **{String}**: The file contents as a UTF-8 string
**Example**
```handlebars
{{read "path/to/file.txt"}}
{{markdown (read "README.md")}}
```
### {{readdir}}
Return an array of files from the given directory. Supports optional filtering by function, RegExp, glob pattern, or type.
**Params**
* `directory` **{String}**: The directory path to read
* `filter` **{Function|RegExp|String}**: Optional filter to apply to the file list
* `returns` **{Array}**: Array of file paths
**Filter Options**
* **Function**: Custom filter function that receives the files array and returns filtered array
* **RegExp**: Regular expression to test against file paths
* **Glob string**: Glob pattern to match files (e.g., `"*.js"`, `"**/*.md"`)
* **"isFile"**: Return only files (not directories)
* **"isDirectory"**: Return only directories (not files)
**Example**
```handlebars
{{#each (readdir "src")}}
{{this}}
{{/each}}
{{#each (readdir "src" "*.js")}}
{{this}}
{{/each}}
{{#each (readdir "src" "isFile")}}
{{this}}
{{/each}}
{{#each (readdir "src" "isDirectory")}}
{{this}}
{{/each}}
{{#each (readdir "posts" "*.md")}}
{{markdown (read this)}}
{{/each}}
```
### Html Helpers
URL: https://fumanchu.org/docs/helpers/html/
Description: Helpers for generating and manipulating HTML elements in templates.
> **Availability**
>
> | Helper | Node | Browser |
> | --- | :---: | :---: |
> | `attr` | โ | โ |
> | `css` | โ | โ |
> | `js` | โ | โ |
> | `ol` | โ | โ |
> | `sanitize` | โ | โ |
> | `thumbnailImage` | โ | โ |
> | `ul` | โ | โ |
### {{attr}}
Stringify attributes from the options hash into an HTML attribute string.
**Params**
* `options` **{Object}**: Options object with a `hash` property containing key-value pairs
* `returns` **{String}**: Space-prefixed attribute string, or empty string if no attributes
**Example**
```handlebars
```
**Output**
```html
```
You can also use variables:
```handlebars
```
**Output**
```html
```
### {{css}}
Generate `` tags for stylesheets. Supports both CSS and LESS files.
**Params**
* `list` **{String|Array}**: One or more stylesheet paths/URLs
* `returns` **{String}**: One or more `` tags
**Example**
Single stylesheet:
```handlebars
{{css "styles/main.css"}}
```
**Output**
```html
```
Multiple stylesheets:
```handlebars
{{css stylesheets}}
```
**Output**
```html
```
LESS files are automatically detected:
```handlebars
{{css "styles/theme.less"}}
```
**Output**
```html
```
### {{js}}
Generate `
```
Multiple scripts:
```handlebars
{{js scripts}}
```
**Output**
```html
```
Using the `src` attribute:
```handlebars
{{js src="bundle.js"}}
```
**Output**
```html
```
### {{sanitize}}
Strip all HTML tags from a string, preserving only the text content.
**Params**
* `str` **{String}**: The string containing HTML to sanitize
* `returns` **{String}**: Plain text with all HTML tags removed
**Example**
```handlebars
{{sanitize "
Hello World!
"}}
```
**Output**
```
Hello World!
```
Extracting text from HTML markup:
```handlebars
{{sanitize richText}}
```
**Output**
```html
Important: Check the docs
```
**Note:** This helper removes HTML tags but preserves all text content, including text inside `