Home

Awesome

handlebars-helpers NPM version NPM monthly downloads NPM total downloads Linux Build Status Windows Build Status

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

Install with npm:

$ npm install --save handlebars-helpers

Install with yarn:

$ yarn add handlebars-helpers

Browser usage

See how to use handlebars-helpers in the browser.

Usage

The main export returns a function that needs to be called to expose the object of helpers.

Get all helpers

var helpers = require('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.

var helpers = require('handlebars-helpers');
var math = helpers.math();
//=> only the `math` helpers

var helpers = require('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.

var helpers = require('handlebars-helpers')(['math', 'string']);
//=> only the `math` and `string` helpers

Optionally pass your own handlebars

var handlebars = require('handlebars');
var helpers = require('handlebars-helpers')({
  handlebars: handlebars
});

// or for a specific collection
var math = helpers.math({
  handlebars: handlebars
});

Helpers

Categories

Currently 189 helpers in 20 categories:

All helpers

array helpers

Visit the: code | unit tests | issues)

code helpers

Visit the: code | unit tests | issues)

collection helpers

Visit the: code | unit tests | issues)

comparison helpers

Visit the: code | unit tests | issues)

date helpers

Visit the: code | unit tests | issues)

fs helpers

Visit the: code | unit tests | issues)

html helpers

Visit the: code | unit tests | issues)

i18n helpers

Visit the: code | unit tests | issues)

inflection helpers

Visit the: code | unit tests | issues)

logging helpers

Visit the: code | unit tests | issues)

markdown helpers

Visit the: code | unit tests | issues)

match helpers

Visit the: code | unit tests | issues)

math helpers

Visit the: code | unit tests | issues)

misc helpers

Visit the: code | unit tests | issues)

number helpers

Visit the: code | unit tests | issues)

object helpers

Visit the: code | unit tests | issues)

path helpers

Visit the: code | unit tests | issues)

regex helpers

Visit the: code | unit tests | issues)

string helpers

Visit the: code | unit tests | issues)

url helpers

Visit the: code | unit tests | issues)


array

{{after}}

Returns all of the items in an array after the specified index. Opposite of before.

Params

Example

<!-- array: ['a', 'b', 'c'] -->
{{after array 1}}
<!-- results in: '["c"]' -->

{{arrayify}}

Cast the given value to an array.

Params

Example

{{arrayify "foo"}}
<!-- results in: [ "foo" ] -->

{{before}}

Return all of the items in the collection before the specified count. Opposite of after.

Params

Example

<!-- array: ['a', 'b', 'c'] -->
{{before array 2}}
<!-- results in: '["a", "b"]' -->

{{eachIndex}}

Params

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

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

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:

Params

Example

<!-- accounts = [
{'name': 'John', 'email': 'john@example.com'},
{'name': 'Malcolm', 'email': 'malcolm@example.com'},
{'name': 'David', 'email': 'david@example.com'}
] -->

{{#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

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

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

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

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

{{last}}

Returns the last item, or last n items of an array or string. Opposite of first.

Params

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

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

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

Example

// {{pluck items "data.title"}}
<!-- results in: '["aa", "bb", "cc"]' -->

{{reverse}}

Reverse the elements in an array, or the characters in a string.

Params

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

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

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

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

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

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

Example

<!-- array: ['a', 'b', 'c'] -->
{{#withFirst array}}
  {{this}}
{{/withFirst}}
<!-- results in: 'a' -->

{{withGroup}}

Block helper that groups array elements by given group size.

Params

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

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

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

Example

<!-- array: ['a', 'a', 'c', 'b', 'e', 'e'] -->
{{#each (unique array)}}{{.}}{{/each}}
<!-- results in: 'acbe' -->

code

{{embed}}

Embed code from an external file as preformatted text.

Params

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

Example

{{gist "12345"}}

{{jsfiddle}}

Generate the HTML for a jsFiddle link with the given params

Params

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

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

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

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

{{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

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

{{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

{{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

{{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

{{has}}

Block helper that renders a block if value has pattern. If an inverse block is specified it will be rendered when falsy.

Params

{{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

{{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

{{ifEven}}

Return true if the given value is an even number.

Params

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

{{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

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

{{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

{{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

{{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

{{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

{{not}}

Returns true if val is falsey. Works as a block or inline helper.

Params

{{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

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

{{unlessGt}}

Block helper that always renders the inverse block unless a is is greater than b.

Params

{{unlessLt}}

Block helper that always renders the inverse block unless a is is less than b.

Params

{{unlessGteq}}

Block helper that always renders the inverse block unless a is is greater than or equal to b.

Params

{{unlessLteq}}

Block helper that always renders the inverse block unless a is is less than or equal to b.

Params

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

Example

{{read "a/b/c.js"}}
{{someHelper (read "a/b/c.md")}}

{{readdir}}

Return an array of files from the given directory.

Params

html

{{attr}}

Stringify attributes on the options hash.

Params

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

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

Example

{{js scripts}}

{{sanitize}}

Strip HTML tags from a string, so that only the text nodes are preserved.

Params

Example

{{sanitize "<span>foo</span>"}}
<!-- results in: 'foo' -->

{{ul}}

Block helper for creating unordered lists (<ul></ul>)

Params

{{ol}}

Block helper for creating ordered lists (<ol></ol>)

Params

{{thumbnailImage}}

Returns a <figure> with a thumbnail linked to a full picture

Params

i18n

{{i18n}}

i18n helper. See button-i18n for a working example.

Params

inflection

{{inflect}}

Returns either the singular or plural inflection of a word based on the given count.

Params

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

Example

{{ordinalize 1}}
<!-- '1st' -->
{{ordinalize 21}}
<!-- '21st' -->
{{ordinalize 29}}
<!-- '29th' -->
{{ordinalize 22}}
<!-- '22nd' -->

logging

logging-helpers.

markdown

{{markdown}}

Block helper that converts a string of inline markdown to HTML.

Params

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

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

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

Example

{{isMatch "foo.md" "*.md"}}
<!-- results in: true -->

math

{{abs}}

Return the magnitude of a.

Params

{{add}}

Return the sum of a plus b.

Params

{{avg}}

Returns the average of all numbers in the given array.

Params

Example

{{avg "[1, 2, 3, 4, 5]"}}
<!-- results in: '3' -->

{{ceil}}

Get the Math.ceil() of the given value.

Params

{{divide}}

Divide a by b

Params

{{floor}}

Get the Math.floor() of the given value.

Params

{{minus}}

Return the difference of a minus b.

Params

{{modulo}}

Get the remainder of a division operation.

Params

{{multiply}}

Return the product of a times b.

Params

{{plus}}

Add a by b.

Params

{{random}}

Generate a random number between two values

Params

{{remainder}}

Get the remainder when a is divided by b.

Params

{{round}}

Round the given number.

Params

{{subtract}}

Return the product of a minus b.

Params

{{sum}}

Returns the sum of all numbers in the given array.

Params

Example

{{sum "[1, 2, 3, 4, 5]"}}
<!-- results in: '15' -->

{{times}}

Multiply number a by number b.

Params

misc

{{option}}

Return the given value of prop from this.options.

Params

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

{{typeOf}}

Get the native type of the given value

Params

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

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:

Params

{{addCommas}}

Add commas to numbers

Params

{{phoneNumber}}

Convert a string or number to a formatted phone number.

Params

{{toAbbr}}

Abbreviate numbers to the given number of precision. This is for general numbers, not size in bytes.

Params

{{toExponential}}

Returns a string representing the given number in exponential notation.

Params

Example

{{toExponential number digits}};

{{toFixed}}

Formats the given number using fixed-point notation.

Params

Example

{{toFixed "1.1234" 2}}
//=> '1.12'

{{toFloat}}

Params

{{toInt}}

Params

{{toPrecision}}

Returns a string representing the Number object to the specified precision.

Params

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

{{forIn}}

Block helper that iterates over the properties of an object, exposing each key and value on the context.

Params

{{forOwn}}

Block helper that iterates over the own properties of an object, exposing each key and value on the context.

Params

{{toPath}}

Take arguments and, if they are string or number, convert them to a dot-delineated object property path.

Params

{{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

{{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

{{hasOwn}}

Return true if key is an own, enumerable property of the given context object.

Params

Example

{{hasOwn context key}}

{{isObject}}

Return true if value is an object.

Params

Example

{{isObject "foo"}}
//=> false

{{JSONparse}}

Parses the given string using JSON.parse.

Params

Example

<!-- string: '{"foo": "bar"}' -->
{{JSONparse string}}
<!-- results in: { foo: 'bar' } -->

{{JSONstringify}}

Stringify an object using JSON.stringify.

Params

Example

<!-- object: { foo: 'bar' } -->
{{JSONstringify object}}
<!-- results in: '{"foo": "bar"}' -->

{{merge}}

Deeply merge the properties of the given objects with the context object.

Params

{{pick}}

Pick properties from the context object.

Params

path

{{absolute}}

Get the directory path segment from the given filepath.

Params

Example

{{absolute "docs/toc.md"}}
<!-- results in: 'docs' -->

{{dirname}}

Get the directory path segment from the given filepath.

Params

Example

{{dirname "docs/toc.md"}}
<!-- results in: 'docs' -->

{{relative}}

Get the relative filepath from a to b.

Params

Example

{{relative a b}}

{{basename}}

Get the file extension from the given filepath.

Params

Example

{{basename "docs/toc.md"}}
<!-- results in: 'toc.md' -->

{{stem}}

Get the "stem" from the given filepath.

Params

Example

{{stem "docs/toc.md"}}
<!-- results in: 'toc' -->

{{extname}}

Get the file extension from the given filepath.

Params

Example

{{extname "docs/toc.md"}}
<!-- results in: '.md' -->

{{resolve}}

Resolve an absolute path from the given filepath.

Params

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

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

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

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

Example

<!-- given that "item.stem" is "foo" -->
{{append item.stem ".html"}}
<!-- results in:  'foo.html' -->

{{camelcase}}

camelCase the characters in the given string.

Params

Example

{{camelcase "foo bar baz"}};
<!-- results in:  'fooBarBaz' -->

{{capitalize}}

Capitalize the first word in a sentence.

Params

Example

{{capitalize "foo bar baz"}}
<!-- results in:  "Foo bar baz" -->

{{capitalizeAll}}

Capitalize all words in a string.

Params

Example

{{capitalizeAll "foo bar baz"}}
<!-- results in:  "Foo Bar Baz" -->

{{center}}

Center a string using non-breaking spaces

Params

{{chop}}

Like trim, but removes both extraneous whitespace and non-word characters from the beginning and end of a string.

Params

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

Example

{{dashcase "a-b-c d_e"}}
<!-- results in:  'a-b-c-d-e' -->

{{dotcase}}

dot.case the characters in string.

Params

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

Example

{{downcase "aBcDeF"}}
<!-- results in:  'abcdef' -->

{{ellipsis}}

Truncates a string to the specified length, and appends it with an elipsis, .

Params

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

Example

{{hyphenate "foo bar baz qux"}}
<!-- results in:  "foo-bar-baz-qux" -->

{{isString}}

Return true if value is a string.

Params

Example

{{isString "foo"}}
<!-- results in:  'true' -->

{{lowercase}}

Lowercase all characters in the given string.

Params

Example

{{lowercase "Foo BAR baZ"}}
<!-- results in:  'foo bar baz' -->

{{occurrences}}

Return the number of occurrences of substring within the given string.

Params

Example

{{occurrences "foo bar foo bar baz" "foo"}}
<!-- results in:  2 -->

{{pascalcase}}

PascalCase the characters in string.

Params

Example

{{pascalcase "foo bar baz"}}
<!-- results in:  'FooBarBaz' -->

{{pathcase}}

path/case the characters in string.

Params

Example

{{pathcase "a-b-c d_e"}}
<!-- results in:  'a/b/c/d/e' -->

{{plusify}}

Replace spaces in the given string with pluses.

Params

Example

{{plusify "foo bar baz"}}
<!-- results in:  'foo+bar+baz' -->

{{prepend}}

Prepends the given string with the specified prefix.

Params

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

Example

{{{{#raw}}}}
{{foo}}
{{{{/raw}}}}
<!-- results in:  '{{foo}}' -->

{{remove}}

Remove all occurrences of substring from the given str.

Params

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

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

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

Example

{{replace "a b a b a b" "a" "z"}}
<!-- results in:  'z b a b a b' -->

{{reverse}}

Reverse a string.

Params

Example

{{reverse "abcde"}}
<!-- results in:  'edcba' -->

{{sentence}}

Sentence case the given string

Params

Example

{{sentence "hello world. goodbye world."}}
<!-- results in:  'Hello world. Goodbye world.' -->

{{snakecase}}

snake_case the characters in the given string.

Params

Example

{{snakecase "a-b-c d_e"}}
<!-- results in:  'a_b_c_d_e' -->

{{split}}

Split string by the given character.

Params

Example

{{split "a,b,c" ","}}
<!-- results in:  ['a', 'b', 'c'] -->

{{startsWith}}

Tests whether a string begins with the given prefix.

Params

Example

{{#startsWith "Goodbye" "Hello, world!"}}
  Whoops
{{else}}
  Bro, do you even hello world?
{{/startsWith}}

{{titleize}}

Title case the given string.

Params

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

Example

{{trim " ABC "}}
<!-- results in:  'ABC' -->

{{trimLeft}}

Removes extraneous whitespace from the beginning of a string.

Params

Example

{{trim " ABC "}}
<!-- results in:  'ABC ' -->

{{trimRight}}

Removes extraneous whitespace from the end of a string.

Params

Example

{{trimRight " ABC "}}
<!-- results in:  ' ABC' -->

{{truncate}}

Truncate a string to the specified length. Also see ellipsis.

Params

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

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

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

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

{{escape}}

Escape the given string by replacing characters with escape sequences. Useful for allowing the string to be used in a URL, etc.

Params

{{decodeURI}}

Decode a Uniform Resource Identifier (URI) component.

Params

{{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

{{urlParse}}

Parses a url string into an object.

Params

{{stripQuerystring}}

Strip the query string from the given url.

Params

{{stripProtocol}}

Strip protocol from a url. Useful for displaying media that may have an 'http' protocol on secure connections.

Params

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

Example

utils.changecase('fooBarBaz');
//=> 'foo bar baz'

utils.changecase('fooBarBaz' '-');
//=> 'foo-bar-baz'

{{random}}

Generate a random number

Params


History

v0.10.0 - 2017-11-17

changes

v0.9.0 - 2017-07-03

changes

v0.8.4 - 2017-07-03

changes

v0.8.3 - 2017-07-03

changes

v0.8.2 - 2017-03-30

changes

v0.8.1 - 2017-03-30

changes

v0.8.0 - 2017-01-25

changes

v0.7.6 - 2017-01-08

changes

v0.7.0 - 2016-07-16

changes

v0.6.0 - 2016-05-13

changes

v0.3.3 - 2013-09-03

changes

v0.3.2 - 2013-08-20

changes

v0.3.0 - 2013-07-30

changes

v0.2.4 - 2013-05-11

changes

v0.2.3 - 2013-05-11

changes

v0.2.0 - 2013-05-07

changes

v0.1.32 - 2013-05-02

changes

v0.1.31 - 2013-04-21

changes

v0.1.30 - 2013-04-20

changes

v0.1.25 - 2013-04-16

changes

v0.1.21 - 2013-04-07

changes

v0.1.20 - 2013-04-06

changes

v0.1.11 - 2013-04-05

changes

v0.1.10 - 2013-04-04

changes

v0.1.8 - 2013-03-28

changes

v0.1.7 - 2013-03-18

changes

v0.1.3 - 2013-03-16

changes

v0.1.2 - 2013-03-15

changes

[v0.1.0] - 2013-03-06

changes

About

Related projects

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Contributors

Release history

Building docs

(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:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

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:

$ npm install && npm test

Author

Brian Woodward

Jon Schlinkert

License

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.