Gathering detailed insights and metrics for handlebars-helpers
Gathering detailed insights and metrics for handlebars-helpers
Gathering detailed insights and metrics for handlebars-helpers
Gathering detailed insights and metrics for handlebars-helpers
@types/handlebars-helpers
TypeScript definitions for handlebars-helpers
handlebars-intl
Handlebars helpers for internationalization.
@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.
newman-reporter-htmlextra
A newman reporter with added handlebars helpers and separated request iterations
188 handlebars helpers in ~20 categories. Can be used with Assemble, Ghost, YUI, express.js etc.
npm install handlebars-helpers
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2,221 Stars
894 Commits
364 Forks
63 Watching
5 Branches
50 Contributors
Updated on 27 Nov 2024
JavaScript (99.94%)
HTML (0.06%)
Cumulative downloads
Total Downloads
Last day
-10.6%
22,072
Compared to previous day
Last week
-3.4%
116,323
Compared to previous week
Last month
13.2%
491,090
Compared to previous month
Last year
10.6%
5,578,467
Compared to previous year
28
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.
You might also be interested in template-helpers.
Install with npm:
1$ npm install --save handlebars-helpers
Install with yarn:
1$ yarn add handlebars-helpers
See how to use handlebars-helpers in the browser.
The main export returns a function that needs to be called to expose the object of helpers.
Get all helpers
1var helpers = require('handlebars-helpers')(); 2//=> 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.
1var helpers = require('handlebars-helpers'); 2var math = helpers.math(); 3//=> only the `math` helpers 4 5var helpers = require('handlebars-helpers'); 6var array = helpers.array(); 7//=> 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.
1var helpers = require('handlebars-helpers')(['math', 'string']); 2//=> only the `math` and `string` helpers
Optionally pass your own handlebars
1var handlebars = require('handlebars'); 2var helpers = require('handlebars-helpers')({ 3 handlebars: handlebars 4}); 5 6// or for a specific collection 7var math = helpers.math({ 8 handlebars: handlebars 9});
Currently 189 helpers in 20 categories:
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
Visit the: code | unit tests | issues)
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
1<!-- array: ['a', 'b', 'c'] --> 2{{after array 1}} 3<!-- results in: '["c"]' -->
Cast the given value
to an array.
Params
value
{any}returns
{Array}Example
1{{arrayify "foo"}} 2<!-- results in: [ "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
1<!-- array: ['a', 'b', 'c'] --> 2{{before array 2}} 3<!-- results in: '["a", "b"]' -->
Params
array
{Array}options
{Object}returns
{String}Example
1<!-- array: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] --> 2{{#eachIndex array}} 3 {{item}} is {{index}} 4{{/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
1<!-- array: ['a', 'b', 'c'] --> 2{{#filter array "foo"}}AAA{{else}}BBB{{/filter}} 3<!-- results in: 'BBB' -->
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
1{{first "['a', 'b', 'c', 'd', 'e']" 2}} 2<!-- results in: '["a", "b"]' -->
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
1<!-- accounts = [ 2{'name': 'John', 'email': 'john@example.com'}, 3{'name': 'Malcolm', 'email': 'malcolm@example.com'}, 4{'name': 'David', 'email': 'david@example.com'} 5] --> 6 7{{#forEach accounts}} 8 <a href="mailto:{{ email }}" title="Send an email to {{ name }}"> 9 {{ name }} 10 </a>{{#unless isLast}}, {{/unless}} 11{{/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
1<!-- array: ['a', 'b', 'c'] --> 2{{#inArray array "d"}} 3 foo 4{{else}} 5 bar 6{{/inArray}} 7<!-- results in: 'bar' -->
Returns true if value
is an es5 array.
Params
value
{any}: The value to test.returns
{Boolean}Example
1{{isArray "abc"}} 2<!-- results in: false --> 3 4<!-- array: [1, 2, 3] --> 5{{isArray array}} 6<!-- results in: true -->
Returns the item from array
at index idx
.
Params
array
{Array}idx
{Number}returns
{any} value
Example
1<!-- array: ['a', 'b', 'c'] --> 2{{itemAt array 1}} 3<!-- results in: 'b' -->
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
1<!-- array: ['a', 'b', 'c'] --> 2{{join array}} 3<!-- results in: 'a, b, c' --> 4 5{{join array '-'}} 6<!-- results in: 'a-b-c' -->
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}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
1<!-- var value = ['a', 'b', 'c', 'd', 'e'] --> 2 3{{last value}} 4<!-- results in: ['e'] --> 5 6{{last value 2}} 7<!-- results in: ['d', 'e'] --> 8 9{{last value 3}} 10<!-- results in: ['c', 'd', 'e'] -->
Returns the length of the given string or array.
Params
value
{Array|Object|String}returns
{Number}: The length of the value.Example
1{{length '["a", "b", "c"]'}} 2<!-- results in: 3 --> 3 4<!-- results in: myArray = ['a', 'b', 'c', 'd', 'e']; --> 5{{length myArray}} 6<!-- results in: 5 --> 7 8<!-- results in: myObject = {'a': 'a', 'b': 'b'}; --> 9{{length myObject}} 10<!-- results in: 2 -->
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
1<!-- array: ['a', 'b', 'c'], and "double" is a 2fictitious function that duplicates letters --> 3{{map array double}} 4<!-- results in: '["aa", "bb", "cc"]' -->
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
1// {{pluck items "data.title"}} 2<!-- results in: '["aa", "bb", "cc"]' -->
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
1<!-- value: 'abcd' --> 2{{reverse value}} 3<!-- results in: 'dcba' --> 4<!-- value: ['a', 'b', 'c', 'd'] --> 5{{reverse value}} 6<!-- results in: ['d', 'c', 'b', 'a'] -->
Block helper that returns the block if the callback returns true for some value in the given array.
Params
array
{Array}iter
{Function}: Iterateereturns
{String}Example
1<!-- array: [1, 'b', 3] --> 2{{#some array isString}} 3 Render me if the array has a string. 4{{else}} 5 Render me if it doesn't. 6{{/some}} 7<!-- results in: 'Render me if the array has a string.' -->
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
1<!-- array: ['b', 'a', 'c'] --> 2{{sort array}} 3<!-- results in: '["a", "b", "c"]' -->
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
1<!-- array: [{a: 'zzz'}, {a: 'aaa'}] --> 2{{sortBy array "a"}} 3<!-- results in: '[{"a":"aaa"}, {"a":"zzz"}]' -->
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
1<!-- array: ['a', 'b', 'c', 'd', 'e'] --> 2{{#withAfter array 3}} 3 {{this}} 4{{/withAfter}} 5<!-- results in: "de" -->
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
1<!-- array: ['a', 'b', 'c', 'd', 'e'] --> 2{{#withBefore array 3}} 3 {{this}} 4{{/withBefore}} 5<!-- results in: 'ab' -->
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
1<!-- array: ['a', 'b', 'c'] --> 2{{#withFirst array}} 3 {{this}} 4{{/withFirst}} 5<!-- results in: 'a' -->
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
1<!-- array: ['a','b','c','d','e','f','g','h'] --> 2{{#withGroup array 4}} 3 {{#each this}} 4 {{.}} 5 {{each}} 6 <br> 7{{/withGroup}} 8<!-- results in: --> 9<!-- 'a','b','c','d'<br> --> 10<!-- 'e','f','g','h'<br> -->
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
1<!-- array: ['a', 'b', 'c'] --> 2{{#withLast array}} 3 {{this}} 4{{/withLast}} 5<!-- results in: 'c' -->
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
1<!-- array: ['b', 'a', 'c'] --> 2{{#withSort array}}{{this}}{{/withSort}} 3<!-- results in: 'abc' -->
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
1<!-- array: ['a', 'a', 'c', 'b', 'e', 'e'] --> 2{{#each (unique array)}}{{.}}{{/each}} 3<!-- results in: 'acbe' -->
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
1{{embed 'path/to/file.js'}} 2<!-- optionally specify the language to use --> 3{{embed 'path/to/file.hbs' 'html')}}
Embed a GitHub Gist using only the id of the Gist
Params
id
{String}returns
{String}Example
1{{gist "12345"}}
Generate the HTML for a jsFiddle link with the given params
Params
params
{Object}returns
{String}Example
1{{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
1<!-- array: [] --> 2{{#isEmpty array}}AAA{{else}}BBB{{/isEmpty}} 3<!-- results in: 'AAA' --> 4 5<!-- array: [] --> 6{{isEmpty array}} 7<!-- results in: true -->
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
{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
1<!-- {great: true, magnificent: true} --> 2{{#and great magnificent}}A{{else}}B{{/and}} 3<!-- results in: 'A' -->
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
1<!-- array = ['a', 'b', 'c'] --> 2{{#contains array "d"}} 3 This will not be rendered. 4{{else}} 5 This will be rendered. 6{{/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
.
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 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
1{{#ifEven value}} 2 render A 3{{else}} 4 render B 5{{/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
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
1{{#ifOdd value}} 2 render A 3{{else}} 4 render B 5{{/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
1{{#or a b c}} 2 If any value is true this will be rendered. 3{{/or}}
Block helper that always renders the inverse block unless a
is
is equal to b
.
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
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.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.Block helper that always renders the inverse block unless a
is
is greater than or equal to b
.
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
is
is less than or equal to b
.
Params
a
{any}b
{any}options
{Object}: Handlebars provided options objectreturns
{String}: Block, or inverse block if specified and falsey.Get the current year.
Example
1{{year}} 2<!-- 2017 -->
Use moment as a helper. See helper-date for more details.
Read a file from the file system. This is useful in composing "include"-style helpers using sub-expressions.
Params
filepath
{String}returns
{String}Example
1{{read "a/b/c.js"}} 2{{someHelper (read "a/b/c.md")}}
Return an array of files from the given directory.
Params
directory
{String}returns
{Array}Stringify attributes on the options hash
.
Params
options
{Object}returns
{String}Example
1<!-- value = 'bar' --> 2<div{{attr foo=value}}></div> 3<!-- results in: <div foo="bar"></div>
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
1<!-- {stylesheets: ['foo.css', 'bar.css']} --> 2{{css stylesheets}} 3 4<!-- results in: --> 5<!-- <link type="text/css" rel="stylesheet" href="foo.css"> --> 6<!-- <link type="text/css" rel="stylesheet" href="bar.css"> -->
Generate one or more <script></script>
tags with paths/urls to javascript or coffeescript files.
Params
context
{Object}returns
{String}Example
1{{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
1{{sanitize "<span>foo</span>"}} 2<!-- results in: 'foo' -->
Block helper for creating unordered lists (<ul></ul>
)
Params
context
{Object}options
{Object}returns
{String}Block helper for creating ordered lists (<ol></ol>
)
Params
context
{Object}options
{Object}returns
{String}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
{String}context.src
{String}context.width
{Number}context.height
{Number}returns
{String}: HTML <figure>
element with image and optional caption/link.i18n helper. See button-i18n for a working example.
Params
key
{String}options
{Object}returns
{String}Returns either the singular
or plural
inflection of a word based on the given count
.
Params
count
{Number}singular
{String}: The singular formplural
{String}: The plural formincludeCount
{String}returns
{String}Example
1{{inflect 0 "string" "strings"}} 2<!-- "strings" --> 3{{inflect 1 "string" "strings"}} 4<!-- "string" --> 5{{inflect 1 "string" "strings" true}} 6<!-- "1 string" --> 7{{inflect 2 "string" "strings"}} 8<!-- "strings" --> 9{{inflect 2 "string" "strings" true}} 10<!-- "2 strings" -->
Returns an ordinalized number as a string.
Params
val
{String}: The value to ordinalize.returns
{String}: The ordinalized numberExample
1{{ordinalize 1}} 2<!-- '1st' --> 3{{ordinalize 21}} 4<!-- '21st' --> 5{{ordinalize 29}} 6<!-- '29th' --> 7{{ordinalize 22}} 8<!-- '22nd' -->
Block helper that converts a string of inline markdown to HTML.
Params
context
{Object}options
{Object}returns
{String}Example
1{{#markdown}} 2# Foo 3{{/markdown}} 4<!-- results in: <h1>Foo</h1> -->
Read a markdown file from the file system and inject its contents after converting it to HTML.
Params
context
{Object}options
{Object}returns
{String}Example
1{{md "foo/bar.md"}}
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
1{{match (readdir "foo") "*.js"}} 2{{match (readdir "foo") (toRegex "\\.js$")}}
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
1{{isMatch "foo.md" "*.md"}} 2<!-- results in: true -->
Return the magnitude of a
.
Params
a
{Number}returns
{Number}Return the sum of a
plus b
.
Params
a
{Number}b
{Number}returns
{Number}Returns the average of all numbers in the given array.
Params
array
{Array}: Array of numbers to add up.returns
{Number}Example
1{{avg "[1, 2, 3, 4, 5]"}} 2<!-- results in: '3' -->
Get the Math.ceil()
of the given value.
Params
value
{Number}returns
{Number}Divide a
by b
Params
a
{Number}: numeratorb
{Number}: denominatorGet the Math.floor()
of the given value.
Params
value
{Number}returns
{Number}Return the difference of a
minus b
.
Params
a
{Number}b
{Number}Get the remainder of a division operation.
Params
a
{Number}b
{Number}returns
{Number}Return the product of a
times b
.
Params
a
{Number}: factorb
{Number}: multiplierreturns
{Number}Add a
by b
.
Params
a
{Number}: factorb
{Number}: multiplierGenerate a random number between two values
Params
min
{Number}max
{Number}returns
{String}Get the remainder when a
is divided by b
.
Params
a
{Number}: ab
{Number}: bRound the given number.
Params
number
{Number}returns
{Number}Return the product of a
minus b
.
Params
a
{Number}b
{Number}returns
{Number}Returns the sum of all numbers in the given array.
Params
array
{Array}: Array of numbers to add up.returns
{Number}Example
1{{sum "[1, 2, 3, 4, 5]"}} 2<!-- results in: '15' -->
Multiply number a
by number b
.
Params
a
{Number}: factorb
{Number}: multiplierreturns
{Number}Return the given value of prop
from this.options
.
Params
prop
{String}returns
{any}Example
1<!-- context = {options: {a: {b: {c: 'ddd'}}}} --> 2{{option "a.b.c"}} 3<!-- results => `ddd` -->
Block helper that renders the block without taking any arguments.
Params
options
{Object}returns
{String}Get the native type of the given value
Params
value
{any}returns
{String}: Returns the type of value.Example
1{{typeOf 1}} 2//=> 'number' 3{{typeOf "1"}} 4//=> 'string' 5{{typeOf "foo"}} 6//=> 'string'
Block helper that builds the context for the block from the options hash.
Params
options
{Object}: Handlebars provided options object.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|String}returns
{String}Add commas to numbers
Params
num
{Number}returns
{Number}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
Abbreviate numbers to the given number of precision
. This is for
general numbers, not size in bytes.
Params
number
{Number}precision
{Number}returns
{String}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
1{{toExponential number digits}};
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
1{{toFixed "1.1234" 2}} 2//=> '1.12'
Params
number
{Number}returns
{Number}Params
number
{Number}returns
{Number}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
1{{toPrecision "1.1234" 2}} 2//=> '1.1'
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}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}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}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}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}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}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
1{{hasOwn context key}}
Return true if value
is an object.
Params
value
{String}returns
{Boolean}Example
1{{isObject "foo"}} 2//=> false
Parses the given string using JSON.parse
.
Params
string
{String}: The string to parseExample
1<!-- string: '{"foo": "bar"}' --> 2{{JSONparse string}} 3<!-- results in: { foo: 'bar' } -->
Stringify an object using JSON.stringify
.
Params
obj
{Object}: Object to stringifyreturns
{String}Example
1<!-- object: { foo: 'bar' } --> 2{{JSONstringify object}} 3<!-- results in: '{"foo": "bar"}' -->
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}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.Get the directory path segment from the given filepath
.
Params
ext
{String}returns
{String}Example
1{{absolute "docs/toc.md"}} 2<!-- results in: 'docs' -->
Get the directory path segment from the given filepath
.
Params
ext
{String}returns
{String}Example
1{{dirname "docs/toc.md"}} 2<!-- results in: 'docs' -->
Get the relative filepath from a
to b
.
Params
a
{String}b
{String}returns
{String}Example
1{{relative a b}}
Get the file extension from the given filepath
.
Params
ext
{String}returns
{String}Example
1{{basename "docs/toc.md"}} 2<!-- results in: 'toc.md' -->
Get the "stem" from the given filepath
.
Params
filepath
{String}returns
{String}Example
1{{stem "docs/toc.md"}} 2<!-- results in: 'toc' -->
Get the file extension from the given filepath
.
Params
filepath
{String}returns
{String}Example
1{{extname "docs/toc.md"}} 2<!-- results in: '.md' -->
Resolve an absolute path from the given filepath
.
Params
filepath
{String}returns
{String}Example
1{{resolve "docs/toc.md"}} 2<!-- results in: '/User/dev/docs/toc.md' -->
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
1{{segments "a/b/c/d" "2" "3"}} 2<!-- results in: 'c/d' --> 3 4{{segments "a/b/c/d" "1" "3"}} 5<!-- results in: 'b/c/d' --> 6 7{{segments "a/b/c/d" "1" "2"}} 8<!-- results in: 'b/c' -->
Convert the given string to a regular expression.
Params
str
{String}returns
{RegExp}Example
1{{toRegex "foo"}} 2<!-- results in: /foo/ -->
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
1{{test "bar" (toRegex "foo")}} 2<!-- results in: false --> 3{{test "foobar" (toRegex "foo")}} 4<!-- results in: true --> 5{{test "foobar" (toRegex "^foo$")}} 6<!-- results in: false -->
Append the specified suffix
to the given string.
Params
str
{String}suffix
{String}returns
{String}Example
1<!-- given that "item.stem" is "foo" --> 2{{append item.stem ".html"}} 3<!-- results in: 'foo.html' -->
camelCase the characters in the given string
.
Params
string
{String}: The string to camelcase.returns
{String}Example
1{{camelcase "foo bar baz"}}; 2<!-- results in: 'fooBarBaz' -->
Capitalize the first word in a sentence.
Params
str
{String}returns
{String}Example
1{{capitalize "foo bar baz"}} 2<!-- results in: "Foo bar baz" -->
Capitalize all words in a string.
Params
str
{String}returns
{String}Example
1{{capitalizeAll "foo bar baz"}} 2<!-- results in: "Foo Bar Baz" -->
Center a string using non-breaking spaces
Params
str
{String}spaces
{String}returns
{String}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
1{{chop "_ABC_"}} 2<!-- results in: 'ABC' --> 3 4{{chop "-ABC-"}} 5<!-- results in: 'ABC' --> 6 7{{chop " ABC "}} 8<!-- results in: 'ABC' -->
dash-case the characters in string
. Replaces non-word characters and periods with hyphens.
Params
string
{String}returns
{String}Example
1{{dashcase "a-b-c d_e"}} 2<!-- results in: 'a-b-c-d-e' -->
dot.case the characters in string
.
Params
string
{String}returns
{String}Example
1{{dotcase "a-b-c d_e"}} 2<!-- results in: 'a.b.c.d.e' -->
Lowercase all of the characters in the given string. Alias for lowercase.
Params
string
{String}returns
{String}Example
1{{downcase "aBcDeF"}} 2<!-- results in: 'abcdef' -->
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
1{{ellipsis (sanitize "<span>foo bar baz</span>"), 7}} 2<!-- results in: 'foo bar…' --> 3{{ellipsis "foo bar baz", 7}} 4<!-- results in: 'foo bar…' -->
Replace spaces in a string with hyphens.
Params
str
{String}returns
{String}Example
1{{hyphenate "foo bar baz qux"}} 2<!-- results in: "foo-bar-baz-qux" -->
Return true if value
is a string.
Params
value
{String}returns
{Boolean}Example
1{{isString "foo"}} 2<!-- results in: 'true' -->
Lowercase all characters in the given string.
Params
str
{String}returns
{String}Example
1{{lowercase "Foo BAR baZ"}} 2<!-- results in: 'foo bar baz' -->
Return the number of occurrences of substring
within the given string
.
Params
str
{String}substring
{String}returns
{Number}: Number of occurrencesExample
1{{occurrences "foo bar foo bar baz" "foo"}} 2<!-- results in: 2 -->
PascalCase the characters in string
.
Params
string
{String}returns
{String}Example
1{{pascalcase "foo bar baz"}} 2<!-- results in: 'FooBarBaz' -->
path/case the characters in string
.
Params
string
{String}returns
{String}Example
1{{pathcase "a-b-c d_e"}} 2<!-- results in: 'a/b/c/d/e' -->
Replace spaces in the given string with pluses.
Params
str
{String}: The input stringreturns
{String}: Input string with spaces replaced by plus signsExample
1{{plusify "foo bar baz"}} 2<!-- results in: 'foo+bar+baz' -->
Prepends the given string
with the specified prefix
.
Params
str
{String}prefix
{String}returns
{String}Example
1<!-- given that "val" is "bar" --> 2{{prepend val "foo-"}} 3<!-- results in: 'foo-bar' -->
Render a block without processing mustache templates inside the block.
Params
options
{Object}returns
{String}Example
1{{{{#raw}}}} 2{{foo}} 3{{{{/raw}}}} 4<!-- results in: '{{foo}}' -->
Remove all occurrences of substring
from the given str
.
Params
str
{String}substring
{String}returns
{String}Example
1{{remove "a b a b a b" "a "}} 2<!-- results in: 'b b b' -->
Remove the first occurrence of substring
from the given str
.
Params
str
{String}substring
{String}returns
{String}Example
1{{remove "a b a b a b" "a"}} 2<!-- results in: ' b a b a b' -->
Replace all occurrences of substring a
with substring b
.
Params
str
{String}a
{String}b
{String}returns
{String}Example
1{{replace "a b a b a b" "a" "z"}} 2<!-- results in: 'z b z b z b' -->
Replace the first occurrence of substring a
with substring b
.
Params
str
{String}a
{String}b
{String}returns
{String}Example
1{{replace "a b a b a b" "a" "z"}} 2<!-- results in: 'z b a b a b' -->
Reverse a string.
Params
str
{String}returns
{String}Example
1{{reverse "abcde"}} 2<!-- results in: 'edcba' -->
Sentence case the given string
Params
str
{String}returns
{String}Example
1{{sentence "hello world. goodbye world."}} 2<!-- results in: 'Hello world. Goodbye world.' -->
snake_case the characters in the given string
.
Params
string
{String}returns
{String}Example
1{{snakecase "a-b-c d_e"}} 2<!-- results in: 'a_b_c_d_e' -->
Split string
by the given character
.
Params
string
{String}: The string to split.returns
{String} character
: Default is an empty string.Example
1{{split "a,b,c" ","}} 2<!-- results in: ['a', 'b', 'c'] -->
Tests whether a string begins with the given prefix.
Params
prefix
{String}testString
{String}options
{String}returns
{String}Example
1{{#startsWith "Goodbye" "Hello, world!"}} 2 Whoops 3{{else}} 4 Bro, do you even hello world? 5{{/startsWith}}
Title case the given string.
Params
str
{String}returns
{String}Example
1{{titleize "this is title case"}} 2<!-- results in: 'This Is Title Case' -->
Removes extraneous whitespace from the beginning and end of a string.
Params
string
{String}: The string to trim.returns
{String}Example
1{{trim " ABC "}} 2<!-- results in: 'ABC' -->
Removes extraneous whitespace from the beginning of a string.
Params
string
{String}: The string to trim.returns
{String}Example
1{{trim " ABC "}} 2<!-- results in: 'ABC ' -->
Removes extraneous whitespace from the end of a string.
Params
string
{String}: The string to trim.returns
{String}Example
1{{trimRight " ABC "}} 2<!-- results in: ' ABC' -->
Truncate a string to the specified length
. Also see ellipsis.
Params
str
{String}limit
{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
1truncate("foo bar baz", 7); 2<!-- results in: 'foo bar' --> 3truncate(sanitize("<span>foo bar baz</span>", 7)); 4<!-- results in: 'foo bar' -->
Truncate a string to have the specified number of words. Also see truncate.
Params
str
{String}limit
{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
1truncateWords("foo bar baz", 1); 2<!-- results in: 'foo…' --> 3truncateWords("foo bar baz", 2); 4<!-- results in: 'foo bar…' --> 5truncateWords("foo bar baz", 3); 6<!-- results in: 'foo bar baz' -->
Uppercase all of the characters in the given string. Alias for uppercase.
Params
string
{String}returns
{String}Example
1{{upcase "aBcDeF"}} 2<!-- results in: 'ABCDEF' -->
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
1{{uppercase "aBcDeF"}} 2<!-- results in: 'ABCDEF' -->
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 stringEscape the given string by replacing characters with escape sequences. Useful for allowing the string to be used in a URL, etc.
Params
str
{String}returns
{String}: Escaped string.Decode a Uniform Resource Identifier (URI) component.
Params
str
{String}returns
{String}Alias for encodeURI.
Alias for decodeURI.
Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag.
Params
base
{String}href
{String}returns
{String}Parses a url
string into an object.
Params
str
{String}: URL stringreturns
{String}: Returns stringified JSONStrip the query string from the given url
.
Params
url
{String}returns
{String}: the url without the queryStringStrip protocol from a url
. Useful for displaying media that may have an 'http' protocol on secure connections.
Params
str
{String}returns
{String}: the url with http protocol strippedExample
1<!-- url = 'http://foo.bar' --> 2{{stripProtocol url}} 3<!-- results in: '//foo.bar' -->
The following utils are exposed on .utils
.
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
1utils.changecase('fooBarBaz'); 2//=> 'foo bar baz' 3 4utils.changecase('fooBarBaz' '-'); 5//=> 'foo-bar-baz'
Generate a random number
Params
min
{Number}max
{Number}returns
{Number}changes
unique
to array helperscss
helper to ensure that path.join() is not called on an absolute URL.changes
fileSize
helper in favor of new bytes
helper, which does the same thing, but returns B
instead of byte
or bytes
.isEmpty
, so it can now be used as an inline or block helperraw
helperpluck
helper to array helpersprepend
and append
helpers to string helpersisTruthy
and isFalsey
comparison helpersescape
and url_encode
and url_decode
URL helpersattr
helper to html helpersyear
helper to date helperstypeOf
and frame
helpers to misc helpersabs
, minus
, modulo
, plus
, times
to math helpersellipsis
helper from html
helpers to string helperstruncate
helper from html
helpers to string helpersreverse
helper from string
helpers to array helperseq
and is
helpers so that eq
is strict equality and is
is notmm
helper, use match
insteadchanges
changes
changes
changes
changes
changes
changes
changes
helpers(['string', 'array'])
will load only the string
and array
helpershelpers.path()
will return all of the path helpers.handlebars-helpers
handlebarsmd
and markdown
helpers, we'll have 100% unit test coverage on helperschanges
changes
changes
changes
changes
changes
changes
changes
changes
changes
changes
changes
changes
changes
changes
changes
changes
changes
changes
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
1$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
1$ npm install && npm test
Brian Woodward
Jon Schlinkert
Copyright © 2017, Jon Schlinkert. When this project was created some helpers were sourced from Swag, by Elving Rodriguez. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on November 17, 2017.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
Found 6/20 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More