fumanchu
Handlebars + Helpers Together
Handlebars + Handlebars-helpers (helpers are now maintained in this project) combined into a single package. Easily use in your nodejs as it is a drop in replacement when using handlebars directly.
We plan to make significant changes over time with this project such as the following:
- (Completed) Remove all dependencies on
handlebars-helpers
and maintain all helpers in this project - (Completed) Migration to
vitest
as a testing framework - (Completed) Migration to
xo
as a linting framework - (In Progress) Migrate to Typescript with full typing support
- (In Progress) Replace module dependencies that are no longer supported with supported ones
- Migration to ESM and CJS support using cross compatible code
- Move to better documentation and examples where it makes sense
- Add in browser support via CDN (this will remove the nodejs specific helpers)
Breaking Changes from v2 to v3
Because of the complexity in the legacy helpers library we have moved to exporting the libraries and a helper function to make it easier to use. Here are the exports:
handlebars
- This is an instance of handlebars library without any helpers. It is the same as callingHandlebars.create()
helpers
- This is a function that takes an object with ahandlebars
key and adds all the helpers to the handlebars instance. This is the same as callinghelpers({ handlebars: handlebars })
createHandlebars
- This is an async function that returns a handlebars instance with all the helpers added. This is the same as callinghelpers({ handlebars: handlebars })
but async.Handlebars
- This is the handlebars library itself. It is the same as callingrequire('handlebars')
Please see the examples below for how to use the library.
Table of Contents
- Usage Nodejs
- Using Handlebars Helpers
- Helpers
- All helpers
- array
- {after}
- {arrayify}
- {before}
- {eachIndex}
- {filter}
- {first}
- {forEach}
- {inArray}
- {isArray}
- {itemAt}
- {join}
- {equalsLength}
- {last}
- {length}
- {lengthEqual}
- {map}
- {pluck}
- {reverse}
- {some}
- {sort}
- {sortBy}
- {withAfter}
- {withBefore}
- {withFirst}
- {withGroup}
- {withLast}
- {withSort}
- {unique}
- {embed}
- {gist}
- {jsfiddle}
- collection
- comparison
- date
- fs
- html
- i18n
- inflection
- logging
- markdown
- match
- math
- misc
- number
- object
- path
- regex
- string
- {append}
- {camelcase}
- {capitalize}
- {capitalizeAll}
- {center}
- {chop}
- {dashcase}
- {dotcase}
- {downcase}
- {ellipsis}
- {hyphenate}
- {isString}
- {lowercase}
- {occurrences}
- {pascalcase}
- {pathcase}
- {plusify}
- {prepend}
- {raw}
- {remove}
- {removeFirst}
- {replace}
- {replaceFirst}
- {reverse}
- {sentence}
- {snakecase}
- {split}
- {startsWith}
- {titleize}
- {trim}
- {trimLeft}
- {trimRight}
- {truncate}
- {truncateWords}
- {upcase}
- {uppercase}
- url
- Utils
- How to Contribute
- License and Copyright
Usage Nodejs
npm install @jaredwray/fumanchu --save
var {handlebars, helpers} = require('@jaredwray/fumanchu');
helpers({ handlebars: handlebars });
var template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
var html = template({foo: 'bar'});
console.log(html);
If using it with es6 you can access handlebars
and helpers
:
import {handlebars, helpers} from '@jaredwray/fumanchu';
helpers({ handlebars: handlebars });
const template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
const html = template({foo: 'bar'});
console.log(html);
If you want to just get an instance of handlebars via createHandlebars
you can do the following (it is async):
import {createHandlebars} from '@jaredwray/fumanchu';
const handlebars = await createHandlebars(); //this will return a handlebars instance with all helpers
const template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
const html = template({foo: 'bar'});
console.log(html); // <p>Foo is bar</p>
It's just that easy! No need to add Handlebars to your project, it's already included.
Using Handlebars Helpers
If you only want to use handlebar helpers you can easily do that by doing the following:
var {helpers} = require('@jaredwray/fumanchu');
var handlebars = require('handlebars');
helpers({ handlebars: handlebars });
var fn = handlebars.compile('{{add value 5}}');
console.log(fn); // 10
If using it with es6 you can access helpers
via destructuring:
import {helpers} from '@jaredwray/fumanchu';
import handlebars from 'handlebars';
helpers({ handlebars: handlebars });
const template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
const html = template({foo: 'bar'});
console.log(html); // <p>Foo is bar</p>
Helpers
More than 180 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.
Categories
Currently 189 helpers in 20 categories:
- array (code | unit tests)
- code (code | unit tests)
- collection (code | unit tests)
- comparison (code | unit tests)
- date (code | unit tests)
- fs (code | unit tests)
- html (code | unit tests)
- i18n (code | unit tests)
- inflection (code | unit tests)
- logging (code | unit tests)
- markdown (code | unit tests)
- match (code | unit tests)
- math (code | unit tests)
- misc (code | unit tests)
- number (code | unit tests)
- object (code | unit tests)
- path (code | unit tests)
- regex (code | unit tests)
- string (code | unit tests)
- url (code | unit tests)
All helpers
array helpers
Visit the: code | unit tests | issues)
- after (code | tests)
- arrayify (code | tests)
- before (code | tests)
- eachIndex (code | tests)
- filter (code | tests)
- first (code | tests)
- forEach (code | tests)
- inArray (code | tests)
- isArray (code | tests)
- itemAt (code | tests)
- join (code | tests)
- equalsLength (code | tests)
- last (code | tests)
- length (code | tests)
- lengthEqual (code | tests)
- map (code | tests)
- pluck (code | tests)
- reverse (code | tests)
- some (code | tests)
- sort (code | tests)
- sortBy (code | tests)
- withAfter (code | tests)
- withBefore (code | tests)
- withFirst (code | tests)
- withGroup (code | tests)
- withLast (code | tests)
- withSort (code | tests)
- unique (code | tests)
code helpers
Visit the: code | unit tests | issues)
collection helpers
Visit the: code | unit tests | issues)
comparison helpers
Visit the: code | unit tests | issues)
- and (code | tests)
- compare (code | tests)
- contains (code | tests)
- default (code | tests)
- eq (code | tests)
- gt (code | tests)
- gte (code | tests)
- has (code | tests)
- isFalsey (code | tests)
- isTruthy (code | tests)
- ifEven (code | tests)
- ifNth (code | tests)
- ifOdd (code | tests)
- is (code | tests)
- isnt (code | tests)
- lt (code | tests)
- lte (code | tests)
- neither (code | tests)
- not (code | tests)
- or (code | tests)
- unlessEq (code | tests)
- unlessGt (code | tests)
- unlessLt (code | tests)
- unlessGteq (code | tests)
- unlessLteq (code | tests)
date helpers
Visit the: code | unit tests | issues)
fs helpers
Visit the: code | unit tests | issues)
html helpers
Visit the: code | unit tests | issues)
- attr (code | tests)
- css (code | tests)
- js (code | tests)
- sanitize (code | tests)
- ul (code | tests)
- ol (code | tests)
- thumbnailImage (code | tests)
i18n helpers
Visit the: code | unit tests | issues)
inflection helpers
Visit the: code | unit tests | issues)
logging helpers
Visit the: code | unit tests | issues)
- log (code | [no tests])
- ok (code | [no tests])
- success (code | [no tests])
- info (code | [no tests])
- warning (code | [no tests])
- warn (code | [no tests])
- error (code | [no tests])
- danger (code | [no tests])
- bold (code | [no tests])
- _debug (code | [no tests])
- _inspect (code | [no tests])
markdown helpers
match helpers
Visit the: code | unit tests | issues)
math helpers
Visit the: code | unit tests | issues)
- abs (code | test)
- add (code | tests)
- avg (code | tests)
- ceil (code | tests)
- divide (code | tests)
- floor (code | tests)
- minus (code | tests)
- modulo (code | tests)
- multiply (code | tests)
- plus (code | tests)
- random (code | tests)
- remainder (code | tests)
- round (code | tests)
- subtract (code | tests)
- sum (code | tests)
- times (code | tests)
misc helpers
Visit the: code | unit tests | issues)
- frame (code | tests)
- option (code | tests)
- noop (code | tests)
- typeOf (code | tests)
- withHash (code | tests)
number helpers
Visit the: code | unit tests | issues)
- bytes (code | tests)
- addCommas (code | tests)
- phoneNumber (code | tests)
- toAbbr (code | tests)
- toExponential (code | tests)
- toFixed (code | tests)
- toFloat (code | tests)
- toInt (code | tests)
- toPrecision (code | tests)
object helpers
Visit the: code | unit tests | issues)
- extend (code | tests)
- forIn (code | tests)
- forOwn (code | tests)
- toPath (code | tests)
- get (code | tests)
- getObject (code | tests)
- hasOwn (code | tests)
- isObject (code | tests)
- JSONparse (code | tests)
- JSONstringify (code | [no tests])
- merge (code | tests)
- parseJSON (code | [no tests])
- pick (code | tests)
- stringify (code | tests)
path helpers
Visit the: code | unit tests | issues)
- absolute (code | tests)
- dirname (code | tests)
- relative (code | tests)
- basename (code | tests)
- stem (code | tests)
- extname (code | tests)
- resolve (code | tests)
- segments (code | tests)
regex helpers
Visit the: code | unit tests | issues)
string helpers
Visit the: code | unit tests | issues)
- append (code | tests)
- camelcase (code | tests)
- capitalize (code | tests)
- capitalizeAll (code | tests)
- center (code | tests)
- chop (code | tests)
- dashcase (code | tests)
- dotcase (code | tests)
- downcase (code | tests)
- ellipsis (code | tests)
- hyphenate (code | tests)
- isString (code | tests)
- lowercase (code | tests)
- occurrences (code | tests)
- pascalcase (code | tests)
- pathcase (code | tests)
- plusify (code | tests)
- prepend (code | tests)
- raw (code | tests)
- remove (code | tests
- removeFirst (code | tests)
- replace (code | tests)
- replaceFirst (code | tests)
- reverse (code | tests)
- sentence (code | tests)
- snakecase (code | tests)
- split (code | tests)
- startsWith (code | tests)
- titleize (code | tests)
- trim (code | tests)
- trimLeft (code | tests)
- trimRight (code | tests)
- truncate (code | tests)
- truncateWords (code | tests))
- upcase (code | tests)
- uppercase (code | tests)
url helpers
Visit the: code | unit tests | issues)
- encodeURI (code | tests)
- escape (code | tests)
- decodeURI (code | tests)
- url_encode (code | tests)
- url_decode (code | tests)
- urlResolve (code | tests)
- urlParse (code | tests)
- stripQuerystring (code | tests)
- stripProtocol (code | tests)
array
{after}
Returns all of the items in an array after the specified index. Opposite of before.
Params
array
Array: Collectionn
Number: Starting index (number of items to exclude)returns
Array: Array exludingn
items.
Example
<!-- array: ['a', 'b', 'c'] -->
{{after array 1}}
<!-- results in: '["c"]' -->
{arrayify}
Cast the given value
to an array.
Params
value
anyreturns
Array
Example
{{arrayify "foo"}}
<!-- results in: [ "foo" ] -->
{before}
Return all of the items in the collection before the specified count. Opposite of after.
Params
array
Arrayn
Numberreturns
Array: Array excluding items after the given number.
Example
<!-- array: ['a', 'b', 'c'] -->
{{before array 2}}
<!-- results in: '["a", "b"]' -->
{eachIndex}
Params
array
Arrayoptions
Objectreturns
String
Example
<!-- array: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] -->
{{#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
Arrayvalue
anyoptions
Objectreturns
String
Example
<!-- array: ['a', 'b', 'c'] -->
{{#filter array "foo"}}AAA{{else}}BBB{{/filter}}
<!-- results in: 'BBB' -->
{first}
Returns the first item, or first n
items of an array.
Params
array
Arrayn
Number: Number of items to return, starting at0
.returns
Array
Example
{{first "['a', 'b', 'c', 'd', 'e']" 2}}
<!-- results in: '["a", "b"]' -->
{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
Arrayreturns
String
Example
<!-- accounts = [
{'name': 'John', 'email': '[email protected]'},
{'name': 'Malcolm', 'email': '[email protected]'},
{'name': 'David', 'email': '[email protected]'}
] -->
{{#forEach accounts}}
<a href="mailto:{{ email }}" title="Send an email to {{ name }}">
{{ name }}
</a>{{#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
Arrayvalue
anyoptions
Objectreturns
String
Example
<!-- array: ['a', 'b', 'c'] -->
{{#inArray array "d"}}
foo
{{else}}
bar
{{/inArray}}
<!-- results in: 'bar' -->
{isArray}
Returns true if value
is an es5 array.
Params
value
any: The value to test.returns
Boolean
Example
{{isArray "abc"}}
<!-- results in: false -->
<!-- array: [1, 2, 3] -->
{{isArray array}}
<!-- results in: true -->
{itemAt}
Returns the item from array
at index idx
.
Params
array
Arrayidx
Numberreturns
anyvalue
Example
<!-- array: ['a', 'b', 'c'] -->
{{itemAt array 1}}
<!-- results in: 'b' -->
{join}
Join all elements of array into a string, optionally using a given separator.
Params
array
Arrayseparator
String: The separator to use. Defaults to,
.returns
String
Example
<!-- array: ['a', 'b', 'c'] -->
{{join array}}
<!-- results in: 'a, b, c' -->
{{join array '-'}}
<!-- results in: 'a-b-c' -->
{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|Stringlength
Numberoptions
Objectreturns
String
{last}
Returns the last item, or last n
items of an array or string. Opposite of first.
Params
value
Array|String: Array or string.n
Number: Number of items to return from the end of the array.returns
Array
Example
<!-- var value = ['a', 'b', 'c', 'd', 'e'] -->
{{last value}}
<!-- results in: ['e'] -->
{{last value 2}}
<!-- results in: ['d', 'e'] -->
{{last value 3}}
<!-- results in: ['c', 'd', 'e'] -->
{length}
Returns the length of the given string or array.
Params
value
Array|Object|Stringreturns
Number: The length of the value.
Example
{{length '["a", "b", "c"]'}}
<!-- results in: 3 -->
<!-- results in: myArray = ['a', 'b', 'c', 'd', 'e']; -->
{{length myArray}}
<!-- results in: 5 -->
<!-- results in: myObject = {'a': 'a', 'b': 'b'}; -->
{{length myObject}}
<!-- results in: 2 -->
{lengthEqual}
Alias for equalsLength
{map}
Returns a new array, created by calling function
on each element of the given array
. For example,
Params
array
Arrayfn
Functionreturns
String
Example
<!-- array: ['a', 'b', 'c'], and "double" is a
fictitious function that duplicates letters -->
{{map array double}}
<!-- results in: '["aa", "bb", "cc"]' -->
{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|Objectprop
Functionreturns
String
Example
// {{pluck items "data.title"}}
<!-- results in: '["aa", "bb", "cc"]' -->
{reverse}
Reverse the elements in an array, or the characters in a string.
Params
value
Array|Stringreturns
Array|String: Returns the reversed string or array.
Example
<!-- value: 'abcd' -->
{{reverse value}}
<!-- results in: 'dcba' -->
<!-- value: ['a', 'b', 'c', 'd'] -->
{{reverse value}}
<!-- results in: ['d', 'c', 'b', 'a'] -->
{some}
Block helper that returns the block if the callback returns true for some value in the given array.
Params
array
Arrayiter
Function: Iteratee- Options: Handlebars provided options object
returns
String
Example
<!-- array: [1, 'b', 3] -->
{{#some array isString}}
Render me if the array has a string.
{{else}}
Render me if it doesn't.
{{/some}}
<!-- results in: 'Render me if the array has a string.' -->
{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
<!-- array: ['b', 'a', 'c'] -->
{{sort array}}
<!-- results in: '["a", "b", "c"]' -->
{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
<!-- array: [{a: 'zzz'}, {a: 'aaa'}] -->
{{sortBy array "a"}}
<!-- results in: '[{"a":"aaa"}, {"a":"zzz"}]' -->
{withAfter}
Use the items in the array after the specified index as context inside a block. Opposite of withBefore.
Params
array
Arrayidx
Numberoptions
Objectreturns
Array
Example
<!-- array: ['a', 'b', 'c', 'd', 'e'] -->
{{#withAfter array 3}}
{{this}}
{{/withAfter}}
<!-- results in: "de" -->
{withBefore}
Use the items in the array before the specified index as context inside a block. Opposite of withAfter.
Params
array
Arrayidx
Numberoptions
Objectreturns
Array
Example
<!-- array: ['a', 'b', 'c', 'd', 'e'] -->
{{#withBefore array 3}}
{{this}}
{{/withBefore}}
<!-- results in: 'ab' -->
{withFirst}
Use the first item in a collection inside a handlebars block expression. Opposite of withLast.
Params
array
Arrayidx
Numberoptions
Objectreturns
String
Example
<!-- array: ['a', 'b', 'c'] -->
{{#withFirst array}}
{{this}}
{{/withFirst}}
<!-- results in: 'a' -->
{withGroup}
Block helper that groups array elements by given group size
.
Params
array
Array: The array to iterate oversize
Number: The desired length of each array "group"options
Object: Handlebars optionsreturns
String
Example
<!-- array: ['a','b','c','d','e','f','g','h'] -->
{{#withGroup array 4}}
{{#each this}}
{{.}}
{{each}}
<br>
{{/withGroup}}
<!-- results in: -->
<!-- 'a','b','c','d'<br> -->
<!-- 'e','f','g','h'<br> -->
{withLast}
Use the last item or n
items in an array as context inside a block. Opposite of withFirst.
Params
array
Arrayidx
Number: The starting index.options
Objectreturns
String
Example
<!-- array: ['a', 'b', 'c'] -->
{{#withLast array}}
{{this}}
{{/withLast}}
<!-- results in: 'c' -->
{withSort}
Block helper that sorts a collection and exposes the sorted collection as context inside the block.
Params
array
Arrayprop
Stringoptions
Object: Specifyreverse="true"
to reverse the array.returns
String
Example
<!-- array: ['b', 'a', 'c'] -->
{{#withSort array}}{{this}}{{/withSort}}
<!-- results in: 'abc' -->
{unique}
Block helper that return an array with all duplicate values removed. Best used along with a each helper.
Params
array
Arrayoptions
Objectreturns
Array
Example
<!-- array: ['a', 'a', 'c', 'b', 'e', 'e'] -->
{{#each (unique array)}}{{.}}{{/each}}
<!-- results in: 'acbe' -->
{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
{{embed 'path/to/file.js'}}
<!-- optionally specify the language to use -->
{{embed 'path/to/file.hbs' 'html')}}
{gist}
Embed a GitHub Gist using only the id of the Gist
Params
id
Stringreturns
String
Example
{{gist "12345"}}
{jsfiddle}
Generate the HTML for a jsFiddle link with the given params
Params
params
Objectreturns
String
Example
{{jsfiddle id="0dfk10ks" tabs="true"}}
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 colleciton is not empty.
Params
collection
Objectoptions
Objectreturns
String
Example
<!-- array: [] -->
{{#isEmpty array}}AAA{{else}}BBB{{/isEmpty}}
<!-- results in: 'AAA' -->
<!-- array: [] -->
{{isEmpty array}}
<!-- results in: true -->
{iterate}
Block helper that iterates over an array or object. If
an array is given, .forEach
is called, or if an object
is given, .forOwn
is called, otherwise the inverse block
is returned.
Params
collection
Object|Array: The collection to iterate overoptions
Objectreturns
String
comparison
{and}
Helper that renders the block if both 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
a
anyb
anyoptions
Object: Handlebars provided options objectreturns
String
Example
<!-- {great: true, magnificent: true} -->
{{#and great magnificent}}A{{else}}B{{/and}}
<!-- results in: 'A' -->
{compare}
Render a block when a comparison of the first and third arguments returns true. The second argument is the arithemetic operator to use. You may also optionally specify an inverse block to render when falsy.
Params
a
operator
: The operator to use. Operators must be enclosed in quotes:">"
,"="
,"<="
, and so on.b
options
Object: Handlebars provided options objectreturns
String: Block, or if specified the inverse block is rendered if falsey.
{contains}
Block helper that renders the block if collection
has the given value
, using strict equality (===
) for comparison, otherwise the inverse block is rendered (if specified). If a startIndex
is specified and is negative, it is used as the offset from the end of the collection.
Params
collection
Array|Object|String: The collection to iterate over.value
any: The value to check for.[startIndex=0]
Number: Optionally define the starting index.options
Object: Handlebars provided options object.
Example
<!-- array = ['a', 'b', 'c'] -->
{{#contains array "d"}}
This will not be rendered.
{{else}}
This will be rendered.
{{/contains}}
{{default}}
Returns the first value that is not undefined, otherwise the default
value is returned.
Params
value
anydefaultValue
anyreturns
String
{eq}
Block helper that renders a block if a
is equal to b
.
If an inverse block is specified it will be rendered when falsy.
You may optionally use the compare=""
hash argument for the
second value.
Params
a
Stringb
Stringoptions
Object: Handlebars provided options objectreturns
String: Block, or inverse block if specified and falsey.
{gt}
Block helper that renders a block if a
is greater than b
.
If an inverse block is specified it will be rendered when falsy.
You may optionally use the compare=""
hash argument for the
second value.
Params
a
Stringb
Stringoptions
Object: Handlebars provided options objectreturns
String: Block, or inverse block if specified and falsey.
{gte}
Block helper that renders a block if a
is greater than or equal to b
.
If an inverse block is specified it will be rendered when falsy.
You may optionally use the compare=""
hash argument for the
second value.
Params
a
Stringb
Stringoptions
Object: Handlebars provided options objectreturns
String: Block, or inverse block if specified and falsey.
{has}
Block helper that renders a block if value
has pattern
.
If an inverse block is specified it will be rendered when falsy.
Params
val
any: The value to check.pattern
any: The pattern to check for.options
Object: Handlebars provided options objectreturns
String
{isFalsey}
Returns true if the given value
is falsey. Uses the falsey
library for comparisons. Please see that library for more information
or to report bugs with this helper.
Params
val
anyoptions
Optionsreturns
Boolean
{isTruthy}
Returns true if the given value
is truthy. Uses the falsey
library for comparisons. Please see that library for more information
or to report bugs with this helper.
Params
val
anyoptions
Optionsreturns
Boolean
{ifEven}
Return true if the given value is an even number.
Params
number
Numberoptions
Object: Handlebars provided options objectreturns
String: Block, or inverse block if specified and falsey.
Example
{{#ifEven value}}
render A
{{else}}
render B
{{/ifEven}}
{ifNth}
Conditionally renders a block if the remainder is zero when
a
operand is divided by b
. If an inverse block is specified
it will be rendered when the remainder is not zero.
Params
- : Number
- : Number
options
Object: Handlebars provided options objectreturns
String: Block, or inverse block if specified and falsey.
{ifOdd}
Block helper that renders a block if value
is an odd number. If an inverse block is specified it will be rendered when falsy.
Params
value
Objectoptions
Object: Handlebars provided options objectreturns
String: Block, or inverse block if specified and falsey.
Example
{{#ifOdd value}}
render A
{{else}}
render B
{{/ifOdd}}
{{is}}
Block helper that renders a block if a
is equal to b
.
If an inverse block is specified it will be rendered when falsy.
Similar to eq but does not do strict equality.
Params
a
anyb
anyoptions
Object: Handlebars provided options objectreturns
String
{{isnt}}
Block helper that renders a block if a
is not equal to b
.
If an inverse block is specified it will be rendered when falsy.
Similar to unlessEq but does not use strict equality for
comparisons.
Params
a
Stringb
Stringoptions
Object: Handlebars provided options objectreturns
String
{{lt}}
Block helper that renders a block if a
is less than b
.
If an inverse block is specified it will be rendered when falsy.
You may optionally use the compare=""
hash argument for the
second value.
Params
context
Objectoptions
Object: Handlebars provided options objectreturns
String: Block, or inverse block if specified and falsey.
{{lte}}
Block helper that renders a block if a
is less than or equal to b
.
If an inverse block is specified it will be rendered when falsy.
You may optionally use the compare=""
hash argument for the
second value.
Params
a
Sringb
Sringoptions
Object: Handlebars provided options objectreturns
String: Block, or inverse block if specified and falsey.
{{neither}}
Block helper that renders a block if neither of the given values are truthy. If an inverse block is specified it will be rendered when falsy.
Params
a
anyb
anyoptions
: Handlebars options objectreturns
String: Block, or inverse block if specified and falsey.
{{not}}
Returns true if val
is falsey. Works as a block or inline helper.
Params
val
Stringoptions
Object: Handlebars provided options objectreturns
String
{{or}}
Block helper that renders a block if any of the given values is truthy. If an inverse block is specified it will be rendered when falsy.
Params
args
any: Variable number of argumentsoptions
Object: Handlebars options objectreturns
String: Block, or inverse block if specified and falsey.
Example
{{#or a b c}}
If any value is true this will be rendered.
{{/or}}
{unlessEq}
Block helper that always renders the inverse block unless a
is
is equal to b
.
Params
a
Stringb
Stringoptions
Object: Handlebars provided options objectreturns
String: Inverse block by default, or block if falsey.
{unlessGt}
Block helper that always renders the inverse block unless a
is
is greater than b
.
Params
a
Object: The default valueb
Object: The value to compareoptions
Object: Handlebars provided options objectreturns
String: Inverse block by default, or block if falsey.
{unlessLt}
Block helper that always renders the inverse block unless a
is
is less than b
.
Params
a
Object: The default valueb
Object: The value to compareoptions
Object: Handlebars provided options objectreturns
String: Block, or inverse block if specified and falsey.
{unlessGteq}
Block helper that always renders the inverse block unless a
is
is greater than or equal to b
.
Params
a
anyb
anyoptions
Object: Handlebars provided options objectreturns
String: Block, or inverse block if specified and falsey.
{unlessLteq}
Block helper that always renders the inverse block unless a
is
is less than or equal to b
.
Params
a
anyb
anyoptions
Object: Handlebars provided options objectreturns
String: Block, or inverse block if specified and falsey.
date
{year}
Get the current year.
Example
{{year}}
<!-- 2017 -->
{moment}
Use moment as a helper. See helper-date for more details.
fs
{read}
Read a file from the file system. This is useful in composing "include"-style helpers using sub-expressions.
Params
filepath
Stringreturns
String
Example
{{read "a/b/c.js"}}
{{someHelper (read "a/b/c.md")}}
{readdir}
Return an array of files from the given directory.
Params
directory
Stringreturns
Array
html
{attr}
Stringify attributes on the options hash
.
Params
options
Objectreturns
String
Example
<!-- value = 'bar' -->
<div{{attr foo=value}}></div>
<!-- results in: <div foo="bar"></div>
{css}
Add an array of <link>
tags. Automatically resolves relative paths to options.assets
if passed on the context.
Params
list
String|Array: One or more stylesheet urls.returns
String
Example
<!-- {stylesheets: ['foo.css', 'bar.css']} -->
{{css stylesheets}}
<!-- results in: -->
<!-- <link type="text/css" rel="stylesheet" href="foo.css"> -->
<!-- <link type="text/css" rel="stylesheet" href="bar.css"> -->
{js}
Generate one or more <script></script>
tags with paths/urls to javascript or coffeescript files.
Params
context
Objectreturns
String
Example
{{js scripts}}
{sanitize}
Strip HTML tags from a string, so that only the text nodes are preserved.
Params
str
String: The string of HTML to sanitize.returns
String
Example
{{sanitize "<span>foo</span>"}}
<!-- results in: 'foo' -->
{ul}
Block helper for creating unordered lists (<ul></ul>
)
Params
context
Objectoptions
Objectreturns
String
{ol}
Block helper for creating ordered lists (<ol></ol>
)
Params
context
Objectoptions
Objectreturns
String
{thumbnailImage}
Returns a <figure>
with a thumbnail linked to a full picture
Params
context
Object: Object with values/attributes to add to the generated elements:context.alt
Stringcontext.src
Stringcontext.width
Numbercontext.height
Numberreturns
String: HTML<figure>
element with image and optional caption/link.
i18n
{i18n}
i18n helper. See button-i18n for a working example.
Params
key
Stringoptions
Objectreturns
String
inflection
{inflect}
Returns either the singular
or plural
inflection of a word based on the given count
.
Params
count
Numbersingular
String: The singular formplural
String: The plural formincludeCount
Stringreturns
String
Example
{{inflect 0 "string" "strings"}}
<!-- "strings" -->
{{inflect 1 "string" "strings"}}
<!-- "string" -->
{{inflect 1 "string" "strings" true}}
<!-- "1 string" -->
{{inflect 2 "string" "strings"}}
<!-- "strings" -->
{{inflect 2 "string" "strings" true}}
<!-- "2 strings" -->
{ordinalize}
Returns an ordinalized number as a string.
Params
val
String: The value to ordinalize.returns
String: The ordinalized number
Example
{{ordinalize 1}}
<!-- '1st' -->
{{ordinalize 21}}
<!-- '21st' -->
{{ordinalize 29}}
<!-- '29th' -->
{{ordinalize 22}}
<!-- '22nd' -->
logging
markdown
{markdown}
Block helper that converts a string of inline markdown to HTML.
Params
context
Objectoptions
Objectreturns
String
Example
{{#markdown}}
# Foo
{{/markdown}}
<!-- results in: <h1>Foo</h1> -->
{md}
Read a markdown file from the file system and inject its contents after converting it to HTML.
Params
context
Objectoptions
Objectreturns
String
Example
{{md "foo/bar.md"}}
match
{match}
Returns an array of strings that match the given glob pattern(s). Options may be passed on the options hash or locals.
Params
files
Array|Stringpatterns
Array|String: One or more glob patterns.locals
Objectoptions
Objectreturns
Array: Array of matches
Example
{{match (readdir "foo") "*.js"}}
{{match (readdir "foo") (toRegex "\\.js$")}}
{isMatch}
Returns true if a filepath contains the given pattern. Options may be passed on the options hash or locals.
Params
filepath
Stringpattern
Stringoptions
Objectreturns
Boolean
Example
{{isMatch "foo.md" "*.md"}}
<!-- results in: true -->
math
{abs}
Return the magnitude of a
.
Params
a
Numberreturns
Number
{add}
Return the sum of a
plus b
.
Params
a
Numberb
Numberreturns
Number
{avg}
Returns the average of all numbers in the given array.
Params
array
Array: Array of numbers to add up.returns
Number
Example
{{avg "[1, 2, 3, 4, 5]"}}
<!-- results in: '3' -->
{ceil}
Get the Math.ceil()
of the given value.
Params
value
Numberreturns
Number
{divide}
Divide a
by b
Params
a
Number: numeratorb
Number: denominator
{floor}
Get the Math.floor()
of the given value.
Params
value
Numberreturns
Number
{minus}
Return the difference of a
minus b
.
Params
a
Numberb
Number
{modulo}
Get the remainder of a division operation.
Params
a
Numberb
Numberreturns
Number
{multiply}
Return the product of a
times b
.
Params
a
Number: factorb
Number: multiplierreturns
Number
{plus}
Add a
by b
.
Params
a
Number: factorb
Number: multiplier
{random}
Generate a random number between two values
Params
min
Numbermax
Numberreturns
String
{remainder}
Get the remainder when a
is divided by b
.
Params
a
Number: ab
Number: b
{round}
Round the given number.
Params
number
Numberreturns
Number
{subtract}
Return the product of a
minus b
.
Params
a
Numberb
Numberreturns
Number
{sum}
Returns the sum of all numbers in the given array.
Params
array
Array: Array of numbers to add up.returns
Number
Example
{{sum "[1, 2, 3, 4, 5]"}}
<!-- results in: '15' -->
{times}
Multiply number a
by number b
.
Params
a
Number: factorb
Number: multiplierreturns
Number
misc
{option}
Return the given value of prop
from this.options
.
Params
prop
Stringreturns
any
Example
<!-- context = {options: {a: {b: {c: 'ddd'}}}} -->
{{option "a.b.c"}}
<!-- results => `ddd` -->
{noop}
Block helper that renders the block without taking any arguments.
Params
options
Objectreturns
String
{typeOf}
Get the native type of the given value
Params
value
anyreturns
String: Returns the type of value.
Example
{{typeOf 1}}
//=> 'number'
{{typeOf "1"}}
//=> 'string'
{{typeOf "foo"}}
//=> 'string'
{withHash}
Block helper that builds the context for the block from the options hash.
Params
options
Object: Handlebars provided options object.
number
{bytes}
Format a number to it's equivalent in bytes. If a string is passed, it's length will be formatted and returned.
Examples:
'foo' => 3 B
13661855 => 13.66 MB
825399 => 825.39 kB
1396 => 1.4 kB
Params
number
Number|Stringreturns
String
{addCommas}
Add commas to numbers
Params
num
Numberreturns
Number
{phoneNumber}
Convert a string or number to a formatted phone number.
Params
num
Number|String: The phone number to format, e.g.8005551212
returns
Number: Formatted phone number:(800) 555-1212
{toAbbr}
Abbreviate numbers to the given number of precision
. This is for
general numbers, not size in bytes.
Params
number
Numberprecision
Numberreturns
String
{toExponential}
Returns a string representing the given number in exponential notation.
Params
number
NumberfractionDigits
Number: Optional. An integer specifying the number of digits to use after the decimal point. Defaults to as many digits as necessary to specify the number.returns
Number
Example
{{toExponential number digits}};
{toFixed}
Formats the given number using fixed-point notation.
Params
number
Numberdigits
Number: (Optional) The number of digits to appear after the decimal point; this may be a value between 0 and 20. If this argument is omitted, it is treated as 0.returns
String: A string representing the given number using fixed-point notation.
Example
{{toFixed "1.1234" 2}}
//=> '1.12'
{toFloat}
Params
number
Numberreturns
Number
{toInt}
Params
number
Numberreturns
Number
{toPrecision}
Returns a string representing the Number
object to the specified precision.
Params
number
Numberprecision
Number: (Optional) An integer specifying the number of significant digits. If precison is not between 1 and 100 (inclusive), it will be coerced to0
.returns
String: A string representing a Number object in fixed-point or exponential notation rounded to precision significant digits.
Example
{{toPrecision "1.1234" 2}}
//=> '1.1'
object
{extend}
Extend the context with the properties of other objects. A shallow merge is performed to avoid mutating the context.
Params
objects
Object: One or more objects to extend.returns
Object
{forIn}
Block helper that iterates over the properties of an object, exposing each key and value on the context.
Params
context
Objectoptions
Objectreturns
String
{forOwn}
Block helper that iterates over the own properties of an object, exposing each key and value on the context.
Params
obj
Object: The object to iterate over.options
Objectreturns
String
{toPath}
Take arguments and, if they are string or number, convert them to a dot-delineated object property path.
Params
prop
String|Number: The property segments to assemble (can be multiple).returns
String
{get}
Use property paths (a.b.c
) to get a value or nested value from
the context. Works as a regular helper or block helper.
Params
prop
String: The property to get, optionally using dot notation for nested properties.context
Object: The context objectoptions
Object: The handlebars options object, if used as a block helper.returns
String
{getObject}
Use property paths (a.b.c
) to get an object from
the context. Differs from the get
helper in that this
helper will return the actual object, including the
given property key. Also, this helper does not work as a
block helper.
Params
prop
String: The property to get, optionally using dot notation for nested properties.context
Object: The context objectreturns
String
{hasOwn}
Return true if key
is an own, enumerable property of the given context
object.
Params
key
Stringcontext
Object: The context object.returns
Boolean
Example
{{hasOwn context key}}
{isObject}
Return true if value
is an object.
Params
value
Stringreturns
Boolean
Example
{{isObject "foo"}}
//=> false
{JSONparse}
Parses the given string using JSON.parse
.
Params
string
String: The string to parse
Example
<!-- string: '{"foo": "bar"}' -->
{{JSONparse string}}
<!-- results in: { foo: 'bar' } -->
{JSONstringify}
Stringify an object using JSON.stringify
.
Params
obj
Object: Object to stringifyreturns
String
Example
<!-- object: { foo: 'bar' } -->
{{JSONstringify object}}
<!-- results in: '{"foo": "bar"}' -->
{merge}
Deeply merge the properties of the given objects
with the
context object.
Params
object
Object: The target object. Pass an empty object to shallow clone.objects
Objectreturns
Object
{pick}
Pick properties from the context object.
Params
properties
Array|String: One or more properties to pick.context
Objectoptions
Object: Handlebars options object.returns
Object: Returns an object with the picked values. If used as a block helper, the values are passed as context to the inner block. If no values are found, the context is passed to the inverse block.
path
{absolute}
Get the directory path segment from the given filepath
.
Params
ext
Stringreturns
String
Example
{{absolute "docs/toc.md"}}
<!-- results in: 'docs' -->
{dirname}
Get the directory path segment from the given filepath
.
Params
ext
Stringreturns
String
Example
{{dirname "docs/toc.md"}}
<!-- results in: 'docs' -->
{relative}
Get the relative filepath from a
to b
.
Params
a
Stringb
Stringreturns
String
Example
{{relative a b}}
{basename}
Get the file extension from the given filepath
.
Params
ext
Stringreturns
String
Example
{{basename "docs/toc.md"}}
<!-- results in: 'toc.md' -->
{stem}
Get the "stem" from the given filepath
.
Params
filepath
Stringreturns
String
Example
{{stem "docs/toc.md"}}
<!-- results in: 'toc' -->
{extname}
Get the file extension from the given filepath
.
Params
filepath
Stringreturns
String
Example
{{extname "docs/toc.md"}}
<!-- results in: '.md' -->
{resolve}
Resolve an absolute path from the given filepath
.
Params
filepath
Stringreturns
String
Example
{{resolve "docs/toc.md"}}
<!-- results in: '/User/dev/docs/toc.md' -->
{segments}
Get specific (joined) segments of a file path by passing a range of array indices.
Params
filepath
String: The file path to split into segments.returns
String: Returns a single, joined file path.
Example
{{segments "a/b/c/d" "2" "3"}}
<!-- results in: 'c/d' -->
{{segments "a/b/c/d" "1" "3"}}
<!-- results in: 'b/c/d' -->
{{segments "a/b/c/d" "1" "2"}}
<!-- results in: 'b/c' -->
regex
{toRegex}
Convert the given string to a regular expression.
Params
str
Stringreturns
RegExp
Example
{{toRegex "foo"}}
<!-- results in: /foo/ -->
{test}
Returns true if the given str
matches the given regex. A regex can be passed on the context, or using the toRegex helper as a subexpression.
Params
str
Stringreturns
RegExp
Example
{{test "bar" (toRegex "foo")}}
<!-- results in: false -->
{{test "foobar" (toRegex "foo")}}
<!-- results in: true -->
{{test "foobar" (toRegex "^foo$")}}
<!-- results in: false -->
string
{append}
Append the specified suffix
to the given string.
Params
str
Stringsuffix
Stringreturns
String
Example
<!-- given that "item.stem" is "foo" -->
{{append item.stem ".html"}}
<!-- results in: 'foo.html' -->
{camelcase}
camelCase the characters in the given string
.
Params
string
String: The string to camelcase.returns
String
Example
{{camelcase "foo bar baz"}};
<!-- results in: 'fooBarBaz' -->
{capitalize}
Capitalize the first word in a sentence.
Params
str
Stringreturns
String
Example
{{capitalize "foo bar baz"}}
<!-- results in: "Foo bar baz" -->
{capitalizeAll}
Capitalize all words in a string.
Params
str
Stringreturns
String
Example
{{capitalizeAll "foo bar baz"}}
<!-- results in: "Foo Bar Baz" -->
{center}
Center a string using non-breaking spaces
Params
str
Stringspaces
Stringreturns
String
{chop}
Like trim, but removes both extraneous whitespace and non-word characters from the beginning and end of a string.
Params
string
String: The string to chop.returns
String
Example
{{chop "_ABC_"}}
<!-- results in: 'ABC' -->
{{chop "-ABC-"}}
<!-- results in: 'ABC' -->
{{chop " ABC "}}
<!-- results in: 'ABC' -->
{dashcase}
dash-case the characters in string
. Replaces non-word characters and periods with hyphens.
Params
string
Stringreturns
String
Example
{{dashcase "a-b-c d_e"}}
<!-- results in: 'a-b-c-d-e' -->
{dotcase}
dot.case the characters in string
.
Params
string
Stringreturns
String
Example
{{dotcase "a-b-c d_e"}}
<!-- results in: 'a.b.c.d.e' -->
{downcase}
Lowercase all of the characters in the given string. Alias for lowercase.
Params
string
Stringreturns
String
Example
{{downcase "aBcDeF"}}
<!-- results in: 'abcdef' -->
{ellipsis}
Truncates a string to the specified length
, and appends it with an elipsis, …
.
Params
str
Stringlength
Number: The desired length of the returned string.returns
String: The truncated string.
Example
{{ellipsis (sanitize "<span>foo bar baz</span>"), 7}}
<!-- results in: 'foo bar…' -->
{{ellipsis "foo bar baz", 7}}
<!-- results in: 'foo bar…' -->
{hyphenate}
Replace spaces in a string with hyphens.
Params
str
Stringreturns
String
Example
{{hyphenate "foo bar baz qux"}}
<!-- results in: "foo-bar-baz-qux" -->
{isString}
Return true if value
is a string.
Params
value
Stringreturns
Boolean
Example
{{isString "foo"}}
<!-- results in: 'true' -->
{lowercase}
Lowercase all characters in the given string.
Params
str
Stringreturns
String
Example
{{lowercase "Foo BAR baZ"}}
<!-- results in: 'foo bar baz' -->
{occurrences}
Return the number of occurrences of substring
within the given string
.
Params
str
Stringsubstring
Stringreturns
Number: Number of occurrences
Example
{{occurrences "foo bar foo bar baz" "foo"}}
<!-- results in: 2 -->
{pascalcase}
PascalCase the characters in string
.
Params
string
Stringreturns
String
Example
{{pascalcase "foo bar baz"}}
<!-- results in: 'FooBarBaz' -->
{pathcase}
path/case the characters in string
.
Params
string
Stringreturns
String
Example
{{pathcase "a-b-c d_e"}}
<!-- results in: 'a/b/c/d/e' -->
{plusify}
Replace spaces in the given string with pluses.
Params
str
String: The input stringreturns
String: Input string with spaces replaced by plus signs
Example
{{plusify "foo bar baz"}}
<!-- results in: 'foo+bar+baz' -->
{prepend}
Prepends the given string
with the specified prefix
.
Params
str
Stringprefix
Stringreturns
String
Example
<!-- given that "val" is "bar" -->
{{prepend val "foo-"}}
<!-- results in: 'foo-bar' -->
{raw}
Render a block without processing mustache templates inside the block.
Params
options
Objectreturns
String
Example
{{{{#raw}}}}
{{foo}}
{{{{/raw}}}}
<!-- results in: '{{foo}}' -->
{remove}
Remove all occurrences of substring
from the given str
.
Params
str
Stringsubstring
Stringreturns
String
Example
{{remove "a b a b a b" "a "}}
<!-- results in: 'b b b' -->
{removeFirst}
Remove the first occurrence of substring
from the given str
.
Params
str
Stringsubstring
Stringreturns
String
Example
{{remove "a b a b a b" "a"}}
<!-- results in: ' b a b a b' -->
{replace}
Replace all occurrences of substring a
with substring b
.
Params
str
Stringa
Stringb
Stringreturns
String
Example
{{replace "a b a b a b" "a" "z"}}
<!-- results in: 'z b z b z b' -->
{replaceFirst}
Replace the first occurrence of substring a
with substring b
.
Params
str
Stringa
Stringb
Stringreturns
String
Example
{{replace "a b a b a b" "a" "z"}}
<!-- results in: 'z b a b a b' -->
{reverse}
Reverse a string.
Params
str
Stringreturns
String
Example
{{reverse "abcde"}}
<!-- results in: 'edcba' -->
{sentence}
Sentence case the given string
Params
str
Stringreturns
String
Example
{{sentence "hello world. goodbye world."}}
<!-- results in: 'Hello world. Goodbye world.' -->
{snakecase}
snake_case the characters in the given string
.
Params
string
Stringreturns
String
Example
{{snakecase "a-b-c d_e"}}
<!-- results in: 'a_b_c_d_e' -->
{split}
Split string
by the given character
.
Params
string
String: The string to split.returns
Stringcharacter
: Default is an empty string.
Example
{{split "a,b,c" ","}}
<!-- results in: ['a', 'b', 'c'] -->
{startsWith}
Tests whether a string begins with the given prefix.
Params
prefix
StringtestString
Stringoptions
Stringreturns
String
Example
{{#startsWith "Goodbye" "Hello, world!"}}
Whoops
{{else}}
Bro, do you even hello world?
{{/startsWith}}
{titleize}
Title case the given string.
Params
str
Stringreturns
String
Example
{{titleize "this is title case"}}
<!-- results in: 'This Is Title Case' -->
{trim}
Removes extraneous whitespace from the beginning and end of a string.
Params
string
String: The string to trim.returns
String
Example
{{trim " ABC "}}
<!-- results in: 'ABC' -->
{trimLeft}
Removes extraneous whitespace from the beginning of a string.
Params
string
String: The string to trim.returns
String
Example
{{trim " ABC "}}
<!-- results in: 'ABC ' -->
{trimRight}
Removes extraneous whitespace from the end of a string.
Params
string
String: The string to trim.returns
String
Example
{{trimRight " ABC "}}
<!-- results in: ' ABC' -->
{truncate}
Truncate a string to the specified length
. Also see ellipsis.
Params
str
Stringlimit
Number: The desired length of the returned string.suffix
String: Optionally supply a string to use as a suffix to denote when the string has been truncated. Otherwise an ellipsis (…
) will be used.returns
String: The truncated string.
Example
truncate("foo bar baz", 7);
<!-- results in: 'foo bar' -->
truncate(sanitize("<span>foo bar baz</span>", 7));
<!-- results in: 'foo bar' -->
{truncateWords}
Truncate a string to have the specified number of words. Also see truncate.
Params
str
Stringlimit
Number: The desired length of the returned string.suffix
String: Optionally supply a string to use as a suffix to denote when the string has been truncated.returns
String: The truncated string.
Example
truncateWords("foo bar baz", 1);
<!-- results in: 'foo…' -->
truncateWords("foo bar baz", 2);
<!-- results in: 'foo bar…' -->
truncateWords("foo bar baz", 3);
<!-- results in: 'foo bar baz' -->
{upcase}
Uppercase all of the characters in the given string. Alias for uppercase.
Params
string
Stringreturns
String
Example
{{upcase "aBcDeF"}}
<!-- results in: 'ABCDEF' -->
{uppercase}
Uppercase all of the characters in the given string. If used as a block helper it will uppercase the entire block. This helper does not support inverse blocks.
Params
str
String: The string to uppercaseoptions
Object: Handlebars options objectreturns
String
Example
{{uppercase "aBcDeF"}}
<!-- results in: 'ABCDEF' -->
url
{encodeURI}
Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character.
Params
str
String: The un-encoded stringreturns
String: The endcoded string
{escape}
Escape the given string by replacing characters with escape sequences. Useful for allowing the string to be used in a URL, etc.
Params
str
Stringreturns
String: Escaped string.
{decodeURI}
Decode a Uniform Resource Identifier (URI) component.
Params
str
Stringreturns
String
{url_encode}
Alias for encodeURI.
{url_decode}
Alias for decodeURI.
{urlResolve}
Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag.
Params
base
Stringhref
Stringreturns
String
{urlParse}
Parses a url
string into an object.
Params
str
String: URL stringreturns
String: Returns stringified JSON
{stripQuerystring}
Strip the query string from the given url
.
Params
url
Stringreturns
String: the url without the queryString
{stripProtocol}
Strip protocol from a url
. Useful for displaying media that may have an 'http' protocol on secure connections.
Params
str
Stringreturns
String: the url with http protocol stripped
Example
<!-- url = 'http://foo.bar' -->
{{stripProtocol url}}
<!-- results in: '//foo.bar' -->
Utils
The following utils are exposed on .utils
.
{changecase}
Change casing on the given string
, optionally passing a delimiter to use between words in the returned string.
Params
string
String: The string to change.returns
String
Example
utils.changecase('fooBarBaz');
//=> 'foo bar baz'
utils.changecase('fooBarBaz' '-');
//=> 'foo-bar-baz'
{random}
Generate a random number
Params
min
Numbermax
Numberreturns
Number
How to Contribute
clone the repository locally and run 'npm i' in the root. Now that you've set up your workspace, you're ready to contribute changes to the fumanchu
repository you can refer to the CONTRIBUTING guide. If you have any questions please feel free to ask by creating an issue and label it question
.
To test the legacy helpers, you can run npm run test:legacy
to run the tests. If you want to test the new helpers, you can run npm run test
.
License and Copyright
MIT and codebase after 2023 will be copyright of Jared Wray.
This is a fork of handlebars-helpers which is licensed under MIT. Initial copyright of handlebars-helpers: 2013-2015, 2017, Jon Schlinkert, Brian Woodward
. Thank you so much for your effort and building this! We have also continued to list all contributors in package.json
to ensure that they are recognized.
Latest's Releases
What's Changed
- moving to helpers folder structure for legacy and src for typescript by @jaredwray in https://github.com/jaredwray/fumanchu/pull/65
- Adding in helper registry by @jaredwray in https://github.com/jaredwray/fumanchu/pull/66
- making it so we are using the logo.svg on readme by @jaredwray in https://github.com/jaredwray/fumanchu/pull/67
- removing console.log in production code by @jaredwray in https://github.com/jaredwray/fumanchu/pull/68
- migrating legacy helper tests to helpers directory by @jaredwray in https://github.com/jaredwray/fumanchu/pull/69
- Adding in xo for typescript by @jaredwray in https://github.com/jaredwray/fumanchu/pull/70
- upgrading mocha to 10.8.2 by @jaredwray in https://github.com/jaredwray/fumanchu/pull/71
- adding in vitest by @jaredwray in https://github.com/jaredwray/fumanchu/pull/72
- adding in FumanchuOptions by @jaredwray in https://github.com/jaredwray/fumanchu/pull/73
- upgrading cacheable to 1.8.4 by @jaredwray in https://github.com/jaredwray/fumanchu/pull/74
Full Changelog: https://github.com/jaredwray/fumanchu/compare/v3.0.0...v3.0.1
Major Breaking change and you can read about it here:
https://github.com/jaredwray/fumanchu?tab=readme-ov-file#breaking-changes-from-v2-to-v3
What's Changed
- upgrading micromatch to 4.0.8 by @jaredwray in https://github.com/jaredwray/fumanchu/pull/62
- upgrading typescript to 5.6.3 by @jaredwray in https://github.com/jaredwray/fumanchu/pull/63
- moving to async createHandlebars function to do dynamic import by @jaredwray in https://github.com/jaredwray/fumanchu/pull/64
Full Changelog: https://github.com/jaredwray/fumanchu/compare/v2.1.0...v3.0.0
What's Changed
- migrating back to commonjs as the project is not ready for ESM by @jaredwray in https://github.com/jaredwray/fumanchu/pull/61
Full Changelog: https://github.com/jaredwray/fumanchu/compare/v2.0.0...v2.1.0