More than 130 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.
npm install @budibase/handlebars-helpers
> More than 130 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.
- Install
- Usage
- Helpers
- Utils
- History
- About
Install with yarn:
``sh`
$ yarn add @budibase/handlebars-helpers
The main export returns a function that needs to be called to expose the object of helpers.
Get all helpers
`js`
var helpers = require('@budibase/handlebars-helpers')();
//=> returns object with all (130+) helpers
Get a specific helper collection
Helper collections are exposed as getters, so only the helpers you want will be required and loaded.
`jsmath
var helpers = require('@budibase/handlebars-helpers');
var math = helpers.math();
//=> only the helpers
var helpers = require('@budibase/handlebars-helpers');
var array = helpers.array();
//=> only the collections helpers`
Get multiple helpers collections
Helper collections are exposed as getters, so only the helpers you want will be required and loaded.
`jsmath
var helpers = require('@budibase/handlebars-helpers')(['math', 'string']);
//=> only the and string helpers`
Optionally pass your own handlebars
`js
var handlebars = require('handlebars');
var helpers = require('@budibase/handlebars-helpers')({
handlebars: handlebars
});
// or for a specific collection
var math = helpers.math({
handlebars: handlebars
});
`
Currently 189 helpers in 20 categories:
* array (code | unit tests)
* code (code | unit tests)
* collection (code | unit tests)
* comparison (code | unit tests)
* html (code | unit tests)
* i18n (code | unit tests)
* inflection (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)
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 | [no tests])
* last (code | tests)
* length (code | tests)
* lengthEqual (code | tests)
* map (code | tests)
* pluck (code | tests)
* reverse (code | [no 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)
Visit the: code | unit tests | issues)
* embed (code | tests)
* gist (code | tests)
* jsfiddle (code | tests)
Visit the: code | unit tests | issues)
* isEmpty (code | tests)
* iterate (code | tests)
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 | [no tests])
* or (code | tests)
* unlessEq (code | tests)
* unlessGt (code | tests)
* unlessLt (code | tests)
* unlessGteq (code | tests)
* unlessLteq (code | tests)
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)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
* inflect (code | tests)
* ordinalize (code | tests)
Visit the: code | unit tests | issues)
* match (code | tests)
* isMatch (code | tests)
* mm (code | [no tests])
Visit the: code | unit tests | issues)
* abs (code | [no tests])
* add (code | tests)
* avg (code | [no tests])
* ceil (code | tests)
* divide (code | tests)
* floor (code | tests)
* minus (code | [no tests])
* modulo (code | [no tests])
* multiply (code | tests)
* plus (code | [no tests])
* random (code | tests)
* remainder (code | tests)
* round (code | tests)
* subtract (code | tests)
* sum (code | tests)
Visit the: code | unit tests | issues)
* frame (code | [no tests])
* option (code | tests)
* noop (code | tests)
* typeOf (code | [no tests])
* withHash (code | tests)
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)
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)
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 | [no tests])
* segments (code | tests)
Visit the: code | unit tests | issues)
* toRegex (code | [no tests])
* test (code | [no tests])
Visit the: code | unit tests | issues)
* append (code | [no tests])
* camelcase (code | tests)
* capitalize (code | tests)
* capitalizeAll (code | tests)
* center (code | tests)
* chop (code | tests)
* dashcase (code | tests)
* dotcase (code | tests)
* downcase (code | [no 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 | [no tests])
* raw (code | [no tests])
* remove (code | [no tests])
* removeFirst (code | [no tests])
* replace (code | tests)
* replaceFirst (code | [no tests])
* reverse (code | tests)
* sentence (code | tests)
* snakecase (code | tests)
* split (code | tests)
* startsWith (code | tests)
* titleize (code | tests)
* trim (code | tests)
* trimLeft (code | [no tests])
* trimRight (code | [no tests])
* truncate (code | tests)
* truncateWords (code | [no tests])
* upcase (code | [no tests])
* uppercase (code | tests)
Visit the: code | unit tests | issues)
* encodeURI (code | tests)
* escape (code | [no tests])
* decodeURI (code | tests)
* urlResolve (code | tests)
* urlParse (code | tests)
* stripQuerystring (code | tests)
* stripProtocol (code | [no tests])
*
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 exluding n items.
Example
`handlebars`
{{after array 1}}
Cast the given value to an array.
Params
* value {any}returns
* {Array}
Example
`handlebars`
{{arrayify "foo"}}
Return all of the items in the collection before the specified count. Opposite of after.
Params
* array {Array}n
* {Number}returns
* {Array}: Array excluding items after the given number.
Example
`handlebars`
{{before array 2}}
Params
* array {Array}options
* {Object}returns
* {String}
Example
`handlebars`
{{#eachIndex array}}
{{item}} is {{index}}
{{/eachIndex}}
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
`handlebars`
{{#filter array "foo"}}AAA{{else}}BBB{{/filter}}
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
`handlebars`
{{first "['a', 'b', 'c', 'd', 'e']" 2}}
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:
* indextotal
* isFirst
* isLast
* @index
Also, is exposed as a private variable, and additional
private variables may be defined as hash arguments.
Params
* array {Array}returns
* {String}
Example
`handlebars
{{#forEach accounts}}
{{ name }}
{{#unless isLast}}, {{/unless}}
{{/forEach}}
`
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
`handlebars`
{{#inArray array "d"}}
foo
{{else}}
bar
{{/inArray}}
Returns true if value is an es5 array.
Params
* value {any}: The value to test.returns
* {Boolean}
Example
`handlebars
{{isArray "abc"}}
{{isArray array}}
`
Returns the item from array at index idx.
Params
* array {Array}idx
* {Number}returns
* {any} value
Example
`handlebars`
{{itemAt array 1}}
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
`handlebars
{{join array}}
{{join array '-'}}
`
Returns true if the the length of the given value is equallength
to the given . Can be used as a block or inline helper.
Params
* value {Array|String}length
* {Number}options
* {Object}returns
* {String}
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
`handlebars
{{last value}}
{{last value 2}}
{{last value 3}}
`
Returns the length of the given string or array.
Params
* value {Array|Object|String}returns
* {Number}: The length of the value.
Example
`handlebars
{{length '["a", "b", "c"]'}}
{{length myArray}}
{{length myObject}}
`
Alias for equalsLength
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
`handlebars`
{{map array double}}
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
`handlebars`
// {{pluck items "data.title"}}
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
`handlebars`
{{reverse value}}
{{reverse value}}
Block helper that returns the block if the callback returns true for some value in the given array.
Params
* array {Array}iter
* {Function}: Iterateereturns
* {Options}: Handlebars provided options object
* {String}
Example
`handlebars`
{{#some array isString}}
Render me if the array has a string.
{{else}}
Render me if it doesn't.
{{/some}}
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
`handlebars`
{{sort array}}
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
`handlebars`
{{sortBy array "a"}}
Use the items in the array _after_ the specified index as context inside a block. Opposite of withBefore.
Params
* array {Array}idx
* {Number}options
* {Object}returns
* {Array}
Example
`handlebars`
{{#withAfter array 3}}
{{this}}
{{/withAfter}}
Use the items in the array _before_ the specified index as context inside a block. Opposite of withAfter.
Params
* array {Array}idx
* {Number}options
* {Object}returns
* {Array}
Example
`handlebars`
{{#withBefore array 3}}
{{this}}
{{/withBefore}}
Use the first item in a collection inside a handlebars block expression. Opposite of withLast.
Params
* array {Array}idx
* {Number}options
* {Object}returns
* {String}
Example
`handlebars`
{{#withFirst array}}
{{this}}
{{/withFirst}}
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
`handlebars`
{{#withGroup array 4}}
{{#each this}}
{{.}}
{{each}}
{{/withGroup}}
Use the last item or n items in an array as context inside a block. Opposite of withFirst.
Params
* array {Array}idx
* {Number}: The starting index.options
* {Object}returns
* {String}
Example
`handlebars`
{{#withLast array}}
{{this}}
{{/withLast}}
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
`handlebars`
{{#withSort array}}{{this}}{{/withSort}}
Block helper that return an array with all duplicate values removed. Best used along with a each helper.
Params
* array {Array}options
* {Object}returns
* {Array}
Example
`handlebars`
{{#each (unique array)}}{{.}}{{/each}}
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
`handlebars`
{{embed 'path/to/file.js'}}
{{embed 'path/to/file.hbs' 'html')}}
Embed a GitHub Gist using only the id of the Gist
Params
* id {String}returns
* {String}
Example
`handlebars`
{{gist "12345"}}
Generate the HTML for a jsFiddle link with the given params
Params
* params {Object}returns
* {String}
Example
`handlebars`
{{jsfiddle id="0dfk10ks" tabs="true"}}
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 {Object}options
* {Object}returns
* {String}
Example
`handlebars
{{#isEmpty array}}AAA{{else}}BBB{{/isEmpty}}
{{isEmpty array}}
`
Block helper that iterates over an array or object. If
an array is given, .forEach is called, or if an object.forOwn
is given, is called, otherwise the inverse block
is returned.
Params
* collection {Object|Array}: The collection to iterate overoptions
* {Object}returns
* {String}
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 {any}b
* {any}options
* {Object}: Handlebars provided options objectreturns
* {String}
Example
`handlebars`
{{#and great magnificent}}A{{else}}B{{/and}}
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.
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
`handlebars`
{{#contains array "d"}}
This will not be rendered.
{{else}}
This will be rendered.
{{/contains}}
Returns the first value that is not undefined, otherwise the "default" value is returned.
Params
* value {any}defaultValue
* {any}returns
* {String}
Block helper that renders a block if a is equal to b.compare=""
If an inverse block is specified it will be rendered when falsy.
You may optionally use the hash argument for the
second value.
Params
* a {String}b
* {String}options
* {Object}: Handlebars provided options objectreturns
* {String}: Block, or inverse block if specified and falsey.
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 {String}b
* {String}options
* {Object}: Handlebars provided options objectreturns
* {String}: Block, or inverse block if specified and falsey.
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 {String}b
* {String}options
* {Object}: Handlebars provided options objectreturns
* {String}: Block, or inverse block if specified and falsey.
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}
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 {any}options
* {Options}returns
* {Boolean}
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 {any}options
* {Options}returns
* {Boolean}
Return true if the given value is an even number.
Params
* number {Number}options
* {Object}: Handlebars provided options objectreturns
* {String}: Block, or inverse block if specified and falsey.
Example
`handlebars`
{{#ifEven value}}
render A
{{else}}
render B
{{/ifEven}}
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.
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 {Object}options
* {Object}: Handlebars provided options objectreturns
* {String}: Block, or inverse block if specified and falsey.
Example
`handlebars`
{{#ifOdd value}}
render A
{{else}}
render B
{{/ifOdd}}
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 {any}b
* {any}options
* {Object}: Handlebars provided options objectreturns
* {String}
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 {String}b
* {String}options
* {Object}: Handlebars provided options objectreturns
* {String}
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 {Object}options
* {Object}: Handlebars provided options objectreturns
* {String}: Block, or inverse block if specified and falsey.
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 {Sring}b
* {Sring}options
* {Object}: Handlebars provided options objectreturns
* {String}: Block, or inverse block if specified and falsey.
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 {any}b
* {any}options
* {}: Handlebars options objectreturns
* {String}: Block, or inverse block if specified and falsey.
Returns true if val is falsey. Works as a block or inline helper.
Params
* val {String}options
* {Object}: Handlebars provided options objectreturns
* {String}
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
* arguments {...any}: Variable number of argumentsoptions
* {Object}: Handlebars options objectreturns
* {String}: Block, or inverse block if specified and falsey.
Example
`handlebars`
{{#or a b c}}
If any value is true this will be rendered.
{{/or}}
Block helper that always renders the inverse block **unless a isb
is equal to **.
Params
* a {String}b
* {String}options
* {Object}: Handlebars provided options objectreturns
* {String}: Inverse block by default, or block if falsey.
Block helper that always renders the inverse block **unless a isb
is greater than **.
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.
Block helper that always renders the inverse block **unless a isb
is less than **.
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.
Block helper that always renders the inverse block **unless a isb
is greater than or equal to **.
Params
* a {any}b
* {any}options
* {Object}: Handlebars provided options objectreturns
* {String}: Block, or inverse block if specified and falsey.
Block helper that always renders the inverse block **unless a isb
is less than or equal to **.
Params
* a {any}b
* {any}options
* {Object}: Handlebars provided options objectreturns
* {String}: Block, or inverse block if specified and falsey.
Stringify attributes on the options hash.
Params
* options {Object}returns
* {String}
Example
`handlebars
{{css stylesheets}}
`
Generate one or more tags with paths/urls to javascript or coffeescript files.
Params
* context {Object}returns
* {String}
Example
`handlebars`
{{js scripts}}
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
`handlebars`
{{sanitize "foo"}}
Block helper for creating unordered lists (
)Params
*
context {Object}
* options {Object}
* returns {String}$3
Block helper for creating ordered lists (
)Params
*
context {Object}
* options {Object}
* returns {String}$3
Returns a
with a thumbnail linked to a full pictureParams
*
context {Object}: Object with values/attributes to add to the generated elements:
* context.alt {String}
* context.src {String}
* context.width {Number}
* context.height {Number}
* returns {String}: HTML element with image and optional caption/link.i18n
$3
i18n helper. See button-i18n
for a working example.
Params
*
key {String}
* options {Object}
* returns {String}inflection
$3
Returns either the
singular or plural inflection of a word based on the given count.Params
*
count {Number}
* singular {String}: The singular form
* plural {String}: The plural form
* includeCount {String}
* returns {String}Example
`handlebars
{{inflect 0 "string" "strings"}}
{{inflect 1 "string" "strings"}}
{{inflect 1 "string" "strings" true}}
{{inflect 2 "string" "strings"}}
{{inflect 2 "string" "strings" true}}
`$3
Returns an ordinalized number as a string.
Params
*
val {String}: The value to ordinalize.
* returns {String}: The ordinalized numberExample
`handlebars
{{ordinalize 1}}
{{ordinalize 21}}
{{ordinalize 29}}
{{ordinalize 22}}
`match
$3
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|String}
* patterns {Array|String}: One or more glob patterns.
* locals {Object}
* options {Object}
* returns {Array}: Array of matchesExample
`handlebars
{{match (readdir "foo") "*.js"}}
{{match (readdir "foo") (toRegex "\\.js$")}}
`$3
Returns true if a filepath contains the given pattern. Options may be passed on the options hash or locals.
Params
*
filepath {String}
* pattern {String}
* options {Object}
* returns {Boolean}Example
`handlebars
{{isMatch "foo.md" "*.md"}}
`math
$3
Return the magnitude of
a.Params
*
a {Number}
* returns {Number}$3
Return the sum of
a plus b.Params
*
a {Number}
* b {Number}
* returns {Number}$3
Returns the average of all numbers in the given array.
Params
*
array {Array}: Array of numbers to add up.
* returns {Number}Example
`handlebars
{{avg "[1, 2, 3, 4, 5]"}}
`$3
Get the
Math.ceil() of the given value.Params
*
value {Number}
* returns {Number}$3
Divide
a by bParams
*
a {Number}: numerator
* b {Number}: denominator$3
Get the
Math.floor() of the given value.Params
*
value {Number}
* returns {Number}$3
Return the difference of
a minus b.Params
*
a {Number}
* b {Number}$3
Get the remainder of a division operation.
Params
*
a {Number}
* b {Number}
* returns {Number}$3
Return the product of
a multiply b.Params
*
a {Number}: factor
* b {Number}: multiplier
* returns {Number}$3
Add
a by b.Params
*
a {Number}: factor
* b {Number}: multiplier$3
Generate a random number between two values
Params
*
min {Number}
* max {Number}
* returns {String}$3
Get the remainder when
a is divided by b.Params
*
a {Number}: a
* b {Number}: b$3
Round the given number.
Params
*
number {Number}
* returns {Number}$3
Return the product of
a minus b.Params
*
a {Number}
* b {Number}
* returns {Number}$3
Returns the sum of all numbers in the given array.
Params
*
array {Array}: Array of numbers to add up.
* returns {Number}Example
`handlebars
{{sum "[1, 2, 3, 4, 5]"}}
`Params
*
a {Number}: factor
* b {Number}: multiplier
* returns {Number}misc
$3
Return the given value of
prop from this.options.Params
*
prop {String}
* returns {any}Example
`handlebars
{{option "a.b.c"}}
`$3
Block helper that renders the block without taking any arguments.
Params
*
options {Object}
* returns {String}$3
Get the native type of the given
valueParams
*
value {any}
* returns {String}: Returns the type of value.Example
`handlebars
{{typeOf 1}}
//=> 'number'
{{typeOf "1"}}
//=> 'string'
{{typeOf "foo"}}
//=> 'string'
`$3
Block helper that builds the context for the block
from the options hash.
Params
*
options {Object}: Handlebars provided options object.number
$3
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 kBParams
*
number {Number|String}
* returns {String}$3
Add commas to numbers
Params
*
num {Number}
* returns {Number}$3
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$3
Abbreviate numbers to the given number of
precision. This is for
general numbers, not size in bytes.Params
*
number {Number}
* precision {Number}
* returns {String}$3
Returns a string representing the given number in exponential notation.
Params
*
number {Number}
* fractionDigits {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
`handlebars
{{toExponential number digits}};
`$3
Formats the given number using fixed-point notation.
Params
*
number {Number}
* digits {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
`handlebars
{{toFixed "1.1234" 2}}
//=> '1.12'
`$3
Params
*
number {Number}
* returns {Number}$3
Params
*
number {Number}
* returns {Number}$3
Returns a string representing the
Number object to the specified precision.Params
*
number {Number}
* precision {Number}: (Optional) An integer specifying the number of significant digits. If precison is not between 1 and 100 (inclusive), it will be coerced to 0.
* returns {String}: A string representing a Number object in fixed-point or exponential notation rounded to precision significant digits.Example
`handlebars
{{toPrecision "1.1234" 2}}
//=> '1.1'
`object
$3
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}$3
Block helper that iterates over the properties of
an object, exposing each key and value on the context.
Params
*
context {Object}
* options {Object}
* returns {String}$3
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 {Object}
* returns {String}$3
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}$3
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 object
* options {Object}: The handlebars options object, if used as a block helper.
* returns {String}$3
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 object
* returns {String}$3
Return true if
key is an own, enumerable property of the given context object.Params
*
key {String}
* context {Object}: The context object.
* returns {Boolean}Example
`handlebars
{{hasOwn context key}}
`$3
Return true if
value is an object.Params
*
value {String}
* returns {Boolean}Example
`handlebars
{{isObject "foo"}}
//=> false
`$3
Parses the given string using
JSON.parse.Params
*
string {String}: The string to parseExample
`handlebars
{{JSONparse string}}
`$3
Stringify an object using
JSON.stringify.Params
*
obj {Object}: Object to stringify
* returns {String}Example
`handlebars
{{JSONstringify object}}
`$3
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 {Object}
* returns {Object}$3
Pick properties from the context object.
Params
*
properties {Array|String}: One or more properties to pick.
* context {Object}
* options {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
$3
Get the directory path segment from the given
filepath.Params
*
ext {String}
* returns {String}Example
`handlebars
{{absolute "docs/toc.md"}}
`$3
Get the directory path segment from the given
filepath.Params
*
ext {String}
* returns {String}Example
`handlebars
{{dirname "docs/toc.md"}}
`$3
Get the relative filepath from
a to b.Params
*
a {String}
* b {String}
* returns {String}Example
`handlebars
{{relative a b}}
`$3
Get the file extension from the given
filepath.Params
*
ext {String}
* returns {String}Example
`handlebars
{{basename "docs/toc.md"}}
`$3
Get the "stem" from the given
filepath.Params
*
filepath {String}
* returns {String}Example
`handlebars
{{stem "docs/toc.md"}}
`$3
Get the file extension from the given
filepath.Params
*
filepath {String}
* returns {String}Example
`handlebars
{{extname "docs/toc.md"}}
`$3
Resolve an absolute path from the given
filepath.Params
*
filepath {String}
* returns {String}Example
`handlebars
{{resolve "docs/toc.md"}}
`$3
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
`handlebars
{{segments "a/b/c/d" "2" "3"}}
{{segments "a/b/c/d" "1" "3"}}
{{segments "a/b/c/d" "1" "2"}}
`regex
$3
Convert the given string to a regular expression.
Params
*
str {String}
* returns {RegExp}Example
`handlebars
{{toRegex "foo"}}
`$3
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 {String}
* returns {RegExp}Example
`handlebars
{{test "bar" (toRegex "foo")}}
{{test "foobar" (toRegex "foo")}}
{{test "foobar" (toRegex "^foo$")}}
`string
$3
Append the specified
suffix to the given string.Params
*
str {String}
* suffix {String}
* returns {String}Example
`handlebars
{{append item.stem ".html"}}
`$3
camelCase the characters in the given
string.Params
*
string {String}: The string to camelcase.
* returns {String}Example
`handlebars
{{camelcase "foo bar baz"}};
`$3
Capitalize the first word in a sentence.
Params
*
str {String}
* returns {String}Example
`handlebars
{{capitalize "foo bar baz"}}
`$3
Capitalize all words in a string.
Params
*
str {String}
* returns {String}Example
`handlebars
{{capitalizeAll "foo bar baz"}}
`$3
Center a string using non-breaking spaces
Params
*
str {String}
* spaces {String}
* returns {String}$3
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
`handlebars
{{chop "_ABC_"}}
{{chop "-ABC-"}}
{{chop " ABC "}}
`$3
dash-case the characters in
string. Replaces non-word characters and periods with hyphens.Params
*
string {String}
* returns {String}Example
`handlebars
{{dashcase "a-b-c d_e"}}
`$3
dot.case the characters in
string.Params
*
string {String}
* returns {String}Example
`handlebars
{{dotcase "a-b-c d_e"}}
`$3
Lowercase all of the characters in the given string. Alias for lowercase.
Params
*
string {String}
* returns {String}Example
`handlebars
{{downcase "aBcDeF"}}
`$3
Truncates a string to the specified
length, and appends it with an elipsis, ….Params
*
str {String}
* length {Number}: The desired length of the returned string.
* returns {String}: The truncated string.Example
`handlebars
{{ellipsis (sanitize "foo bar baz") 7}}
{{ellipsis "foo bar baz" 7}}
`$3
Replace spaces in a string with hyphens.
Params
*
str {String}
* returns {String}Example
`handlebars
{{hyphenate "foo bar baz qux"}}
`$3
Return true if
value is a string.Params
*
value {String}
* returns {Boolean}Example
`handlebars
{{isString "foo"}}
`$3
Lowercase all characters in the given string.
Params
*
str {String}
* returns {String}Example
`handlebars
{{lowercase "Foo BAR baZ"}}
`$3
Return the number of occurrences of
substring within the given string.Params
*
str {String}
* substring {String}
* returns {Number}: Number of occurrencesExample
`handlebars
{{occurrences "foo bar foo bar baz" "foo"}}
`$3
PascalCase the characters in
string.Params
*
string {String}
* returns {String}Example
`handlebars
{{pascalcase "foo bar baz"}}
`$3
path/case the characters in
string.Params
*
string {String}
* returns {String}Example
`handlebars
{{pathcase "a-b-c d_e"}}
`$3
Replace spaces in the given string with pluses.
Params
*
str {String}: The input string
* returns {String}: Input string with spaces replaced by plus signsExample
`handlebars
{{plusify "foo bar baz"}}
`$3
Prepends the given
string with the specified prefix.Params
*
str {String}
* prefix {String}
* returns {String}Example
`handlebars
{{prepend val "foo-"}}
`$3
Render a block without processing mustache templates inside the block.
Params
*
options {Object}
* returns {String}Example
`handlebars
{{{{#raw}}}}
{{foo}}
{{{{/raw}}}}
`$3
Remove all occurrences of
substring from the given str.Params
*
str {String}
* substring {String}
* returns {String}Example
`handlebars
{{remove "a b a b a b" "a "}}
`$3
Remove the first occurrence of
substring from the given str.Params
*
str`