Getting Started

Table of Contents

Handlebars + Helpers Together

tests codecov npm version GitHub license npm

Handlebars + Handlebars-helpers (helpers are now maintained in this project) combined into a single package. Easily use it as a drop in replacement when using handlebars directly.

Table of Contents

Usage Nodejs

npm install @jaredwray/fumanchu --save
var {handlebars, helpers} = require('@jaredwray/fumanchu');
helpers({ handlebars: handlebars });
var template = handlebars.compile('{{#if (eq foo "bar")}}

Foo is bar

{{/if}}'
); var html = template({foo: 'bar'}); console.log(html);

If using it with es6 you can access handlebars and helpers:

import {handlebars, helpers} from '@jaredwray/fumanchu';
helpers({ handlebars: handlebars });
const template = handlebars.compile('{{#if (eq foo "bar")}}

Foo is bar

{{/if}}'
); const html = template({foo: 'bar'}); console.log(html);

If you want to just get an instance of handlebars via createHandlebars you can do the following (it is async):

import {createHandlebars} from '@jaredwray/fumanchu';
const handlebars = await createHandlebars(); //this will return a handlebars instance with all helpers
const template = handlebars.compile('{{#if (eq foo "bar")}}

Foo is bar

{{/if}}'
); const html = template({foo: 'bar'}); console.log(html); //

Foo is bar

It's just that easy! No need to add Handlebars to your project, it's already included.

Using Handlebars Helpers

If you only want to use handlebar helpers you can easily do that by doing the following:

var {helpers} = require('@jaredwray/fumanchu');
var handlebars = require('handlebars');
helpers({ handlebars: handlebars });
var fn = handlebars.compile('{{add value 5}}');
console.log(fn); // 10

If using it with es6 you can access helpers via destructuring:

import {helpers} from '@jaredwray/fumanchu';
import handlebars from 'handlebars';
helpers({ handlebars: handlebars });
const template = handlebars.compile('{{#if (eq foo "bar")}}

Foo is bar

{{/if}}'
); const html = template({foo: 'bar'}); console.log(html); //

Foo is bar

Helpers

More than 180 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project.

Categories

Currently 189 helpers in 20 categories:

All helpers

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

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)

{embed}

Embed code from an external file as preformatted text.

Params

  • filepath String: filepath to the file to embed.
  • language String: Optionally specify the language to use for syntax highlighting.
  • returns String

Example

{{embed 'path/to/file.js'}}

{{embed 'path/to/file.hbs' 'html')}}

{gist}

Embed a GitHub Gist using only the id of the Gist

Params

  • id String
  • returns String

Example

{{gist "12345"}}

{jsfiddle}

Generate the HTML for a jsFiddle link with the given params

Params

  • params Object
  • returns String

Example

{{jsfiddle id="0dfk10ks" tabs="true"}}

collection

{isEmpty}

Inline, subexpression, or block helper that returns true (or the block) if the given collection is empty, or false (or the inverse block, if supplied) if the colleciton is not empty.

Params

  • collection Object
  • options Object
  • returns String

Example


{{#isEmpty array}}AAA{{else}}BBB{{/isEmpty}}



{{isEmpty array}}

{iterate}

Block helper that iterates over an array or object. If an array is given, .forEach is called, or if an object is given, .forOwn is called, otherwise the inverse block is returned.

Params

  • collection Object|Array: The collection to iterate over
  • options Object
  • returns String

comparison

{and}

Helper that renders the block if both of the given values are truthy. If an inverse block is specified it will be rendered when falsy. Works as a block helper, inline helper or subexpression.

Params

  • a any
  • b any
  • options Object: Handlebars provided options object
  • returns String

Example


{{#and great magnificent}}A{{else}}B{{/and}}

{compare}

Render a block when a comparison of the first and third arguments returns true. The second argument is the arithemetic operator to use. You may also optionally specify an inverse block to render when falsy.

Params

  • a
  • operator : The operator to use. Operators must be enclosed in quotes: ">", "=", "<=", and so on.
  • b
  • options Object: Handlebars provided options object
  • returns String: Block, or if specified the inverse block is rendered if falsey.

{contains}

Block helper that renders the block if collection has the given value, using strict equality (===) for comparison, otherwise the inverse block is rendered (if specified). If a startIndex is specified and is negative, it is used as the offset from the end of the collection.

Params

  • collection Array|Object|String: The collection to iterate over.
  • value any: The value to check for.
  • [startIndex=0] Number: Optionally define the starting index.
  • options Object: Handlebars provided options object.

Example


{{#contains array "d"}}
  This will not be rendered.
{{else}}
  This will be rendered.
{{/contains}}

{{default}}

Returns the first value that is not undefined, otherwise the default value is returned.

Params

  • value any
  • defaultValue any
  • returns String

{eq}

Block helper that renders a block if a is equal to b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare="" hash argument for the second value.

Params

  • a String
  • b String
  • options Object: Handlebars provided options object
  • returns String: Block, or inverse block if specified and falsey.

{gt}

Block helper that renders a block if a is greater than b.

If an inverse block is specified it will be rendered when falsy. You may optionally use the compare="" hash argument for the second value.

Params

  • a String
  • b String
  • options Object: Handlebars provided options object
  • returns String: Block, or inverse block if specified and falsey.

{gte}

Block helper that renders a block if a is greater than or equal to b.

If an inverse block is specified it will be rendered when falsy. You may optionally use the compare="" hash argument for the second value.

Params

  • a String
  • b String
  • options Object: Handlebars provided options object
  • returns String: Block, or inverse block if specified and falsey.

{has}

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

Params

  • val any: The value to check.
  • pattern any: The pattern to check for.
  • options Object: Handlebars provided options object
  • returns String

{isFalsey}

Returns true if the given value is falsey. Uses the falsey library for comparisons. Please see that library for more information or to report bugs with this helper.

Params

  • val any
  • options Options
  • returns Boolean

{isTruthy}

Returns true if the given value is truthy. Uses the falsey library for comparisons. Please see that library for more information or to report bugs with this helper.

Params

  • val any
  • options Options
  • returns Boolean

{ifEven}

Return true if the given value is an even number.

Params

  • number Number
  • options Object: Handlebars provided options object
  • returns String: Block, or inverse block if specified and falsey.

Example

{{#ifEven value}}
  render A
{{else}}
  render B
{{/ifEven}}

{ifNth}

Conditionally renders a block if the remainder is zero when a operand is divided by b. If an inverse block is specified it will be rendered when the remainder is not zero.

Params

  • : Number
  • : Number
  • options Object: Handlebars provided options object
  • returns String: Block, or inverse block if specified and falsey.

{ifOdd}

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

Params

  • value Object
  • options Object: Handlebars provided options object
  • returns String: Block, or inverse block if specified and falsey.

Example

{{#ifOdd value}}
  render A
{{else}}
  render B
{{/ifOdd}}

{{is}}

Block helper that renders a block if a is equal to b. If an inverse block is specified it will be rendered when falsy. Similar to eq but does not do strict equality.

Params

  • a any
  • b any
  • options Object: Handlebars provided options object
  • returns String

{{isnt}}

Block helper that renders a block if a is not equal to b. If an inverse block is specified it will be rendered when falsy. Similar to unlessEq but does not use strict equality for comparisons.

Params

  • a String
  • b String
  • options Object: Handlebars provided options object
  • returns String

{{lt}}

Block helper that renders a block if a is less than b.

If an inverse block is specified it will be rendered when falsy. You may optionally use the compare="" hash argument for the second value.

Params

  • context Object
  • options Object: Handlebars provided options object
  • returns String: Block, or inverse block if specified and falsey.

{{lte}}

Block helper that renders a block if a is less than or equal to b.

If an inverse block is specified it will be rendered when falsy. You may optionally use the compare="" hash argument for the second value.

Params

  • a Sring
  • b Sring
  • options Object: Handlebars provided options object
  • returns String: Block, or inverse block if specified and falsey.

{{neither}}

Block helper that renders a block if neither of the given values are truthy. If an inverse block is specified it will be rendered when falsy.

Params

  • a any
  • b any
  • options : Handlebars options object
  • returns String: Block, or inverse block if specified and falsey.

{{not}}

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

Params

  • val String
  • options Object: Handlebars provided options object
  • returns String

{{or}}

Block helper that renders a block if any of the given values is truthy. If an inverse block is specified it will be rendered when falsy.

Params

  • args any: Variable number of arguments
  • options Object: Handlebars options object
  • returns String: Block, or inverse block if specified and falsey.

Example

{{#or a b c}}
  If any value is true this will be rendered.
{{/or}}

{unlessEq}

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

Params

  • a String
  • b String
  • options Object: Handlebars provided options object
  • returns String: Inverse block by default, or block if falsey.

{unlessGt}

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

Params

  • a Object: The default value
  • b Object: The value to compare
  • options Object: Handlebars provided options object
  • returns String: Inverse block by default, or block if falsey.

{unlessLt}

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

Params

  • a Object: The default value
  • b Object: The value to compare
  • options Object: Handlebars provided options object
  • returns String: Block, or inverse block if specified and falsey.

{unlessGteq}

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

Params

  • a any
  • b any
  • options Object: Handlebars provided options object
  • returns String: Block, or inverse block if specified and falsey.

{unlessLteq}

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

Params

  • a any
  • b any
  • options Object: Handlebars provided options object
  • returns String: Block, or inverse block if specified and falsey.

date

{year}

Get the current year.

Example

{{year}}

{moment}

Use moment as a helper. See helper-date for more details.

fs

{read}

Read a file from the file system. This is useful in composing "include"-style helpers using sub-expressions.

Params

  • filepath String
  • returns String

Example

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

{readdir}

Return an array of files from the given directory.

Params

  • directory String
  • returns Array

html

{attr}

Stringify attributes on the options hash.

Params

  • options Object
  • returns String

Example


div>

{{css stylesheets}}




{js}

Generate one or more tags with paths/urls to javascript or coffeescript files.

Params

  • context Object
  • returns String

Example

{{js scripts}}

{sanitize}

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

Params

  • str String: The string of HTML to sanitize.
  • returns String

Example

{{sanitize "<span>foospan>"}}

{ul}

Block helper for creating unordered lists (

    )

    Params

    • context Object
    • options Object
    • returns String

    {ol}

    Block helper for creating ordered lists (

      )

      Params

      • context Object
      • options Object
      • returns String

      {thumbnailImage}

      Returns a

      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
        element with image and optional caption/link.

      i18n

      {i18n}

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

      Params

      • key String
      • options Object
      • returns String

      inflection

      {inflect}

      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

      {{inflect 0 "string" "strings"}}
      
      {{inflect 1 "string" "strings"}}
      
      {{inflect 1 "string" "strings" true}}
      
      {{inflect 2 "string" "strings"}}
      
      {{inflect 2 "string" "strings" true}}
      
      

      {ordinalize}

      Returns an ordinalized number as a string.

      Params

      • val String: The value to ordinalize.
      • returns String: The ordinalized number

      Example

      {{ordinalize 1}}
      
      {{ordinalize 21}}
      
      {{ordinalize 29}}
      
      {{ordinalize 22}}
      
      

      logging

      logging-helpers.

      markdown

      {markdown}

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

      Params

      • context Object
      • options Object
      • returns String

      Example

      {{#markdown}}
      # Foo
      {{/markdown}}
      
      

      {md}

      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

      {{md "foo/bar.md"}}
      

      match

      {match}

      Returns an array of strings that match the given glob pattern(s). Options may be passed on the options hash or locals.

      Params

      • files Array|String
      • patterns Array|String: One or more glob patterns.
      • locals Object
      • options Object
      • returns Array: Array of matches

      Example

      {{match (readdir "foo") "*.js"}}
      {{match (readdir "foo") (toRegex "\\.js$")}}
      

      {isMatch}

      Returns true if a filepath contains the given pattern. Options may be passed on the options hash or locals.

      Params

      • filepath String
      • pattern String
      • options Object
      • returns Boolean

      Example

      {{isMatch "foo.md" "*.md"}}
      
      

      math

      {abs}

      Return the magnitude of a.

      Params

      • a Number
      • returns Number

      {add}

      Return the sum of a plus b.

      Params

      • a Number
      • b Number
      • returns Number

      {avg}

      Returns the average of all numbers in the given array.

      Params

      • array Array: Array of numbers to add up.
      • returns Number

      Example

      {{avg "[1, 2, 3, 4, 5]"}}
      
      

      {ceil}

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

      Params

      • value Number
      • returns Number

      {divide}

      Divide a by b

      Params

      • a Number: numerator
      • b Number: denominator

      {floor}

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

      Params

      • value Number
      • returns Number

      {minus}

      Return the difference of a minus b.

      Params

      • a Number
      • b Number

      {modulo}

      Get the remainder of a division operation.

      Params

      • a Number
      • b Number
      • returns Number

      {multiply}

      Return the product of a times b.

      Params

      • a Number: factor
      • b Number: multiplier
      • returns Number

      {plus}

      Add a by b.

      Params

      • a Number: factor
      • b Number: multiplier

      {random}

      Generate a random number between two values

      Params

      • min Number
      • max Number
      • returns String

      {remainder}

      Get the remainder when a is divided by b.

      Params

      • a Number: a
      • b Number: b

      {round}

      Round the given number.

      Params

      • number Number
      • returns Number

      {subtract}

      Return the product of a minus b.

      Params

      • a Number
      • b Number
      • returns Number

      {sum}

      Returns the sum of all numbers in the given array.

      Params

      • array Array: Array of numbers to add up.
      • returns Number

      Example

      {{sum "[1, 2, 3, 4, 5]"}}
      
      

      {times}

      Multiply number a by number b.

      Params

      • a Number: factor
      • b Number: multiplier
      • returns Number

      misc

      {option}

      Return the given value of prop from this.options.

      Params

      • prop String
      • returns any

      Example

      
      {{option "a.b.c"}}
      
      

      {noop}

      Block helper that renders the block without taking any arguments.

      Params

      • options Object
      • returns String

      {typeOf}

      Get the native type of the given value

      Params

      • value any
      • returns String: Returns the type of value.

      Example

      {{typeOf 1}}
      //=> 'number'
      {{typeOf "1"}}
      //=> 'string'
      {{typeOf "foo"}}
      //=> 'string'
      

      {withHash}

      Block helper that builds the context for the block from the options hash.

      Params

      • options Object: Handlebars provided options object.

      number

      {bytes}

      Format a number to it's equivalent in bytes. If a string is passed, it's length will be formatted and returned.

      Examples:

      • 'foo' => 3 B
      • 13661855 => 13.66 MB
      • 825399 => 825.39 kB
      • 1396 => 1.4 kB

      Params

      • number Number|String
      • returns String

      {addCommas}

      Add commas to numbers

      Params

      • num Number
      • returns Number

      {phoneNumber}

      Convert a string or number to a formatted phone number.

      Params

      • num Number|String: The phone number to format, e.g. 8005551212
      • returns Number: Formatted phone number: (800) 555-1212

      {toAbbr}

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

      Params

      • number Number
      • precision Number
      • returns String

      {toExponential}

      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

      {{toExponential number digits}};
      

      {toFixed}

      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

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

      {toFloat}

      Params

      • number Number
      • returns Number

      {toInt}

      Params

      • number Number
      • returns Number

      {toPrecision}

      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

      {{toPrecision "1.1234" 2}}
      //=> '1.1'
      

      object

      {extend}

      Extend the context with the properties of other objects. A shallow merge is performed to avoid mutating the context.

      Params

      • objects Object: One or more objects to extend.
      • returns Object

      {forIn}

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

      Params

      • context Object
      • options Object
      • returns String

      {forOwn}

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

      Params

      • obj Object: The object to iterate over.
      • options Object
      • returns String

      {toPath}

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

      Params

      • prop String|Number: The property segments to assemble (can be multiple).
      • returns String

      {get}

      Use property paths (a.b.c) to get a value or nested value from the context. Works as a regular helper or block helper.

      Params

      • prop String: The property to get, optionally using dot notation for nested properties.
      • context Object: The context object
      • options Object: The handlebars options object, if used as a block helper.
      • returns String

      {getObject}

      Use property paths (a.b.c) to get an object from the context. Differs from the get helper in that this helper will return the actual object, including the given property key. Also, this helper does not work as a block helper.

      Params

      • prop String: The property to get, optionally using dot notation for nested properties.
      • context Object: The context object
      • returns String

      {hasOwn}

      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

      {{hasOwn context key}}
      

      {isObject}

      Return true if value is an object.

      Params

      • value String
      • returns Boolean

      Example

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

      {JSONparse}

      Parses the given string using JSON.parse.

      Params

      • string String: The string to parse

      Example

      
      {{JSONparse string}}
      
      

      {JSONstringify}

      Stringify an object using JSON.stringify.

      Params

      • obj Object: Object to stringify
      • returns String

      Example

      
      {{JSONstringify object}}
      
      

      {merge}

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

      Params

      • object Object: The target object. Pass an empty object to shallow clone.
      • objects Object
      • returns Object

      {pick}

      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

      {absolute}

      Get the directory path segment from the given filepath.

      Params

      • ext String
      • returns String

      Example

      {{absolute "docs/toc.md"}}
      
      

      {dirname}

      Get the directory path segment from the given filepath.

      Params

      • ext String
      • returns String

      Example

      {{dirname "docs/toc.md"}}
      
      

      {relative}

      Get the relative filepath from a to b.

      Params

      • a String
      • b String
      • returns String

      Example

      {{relative a b}}
      

      {basename}

      Get the file extension from the given filepath.

      Params

      • ext String
      • returns String

      Example

      {{basename "docs/toc.md"}}
      
      

      {stem}

      Get the "stem" from the given filepath.

      Params

      • filepath String
      • returns String

      Example

      {{stem "docs/toc.md"}}
      
      

      {extname}

      Get the file extension from the given filepath.

      Params

      • filepath String
      • returns String

      Example

      {{extname "docs/toc.md"}}
      
      

      {resolve}

      Resolve an absolute path from the given filepath.

      Params

      • filepath String
      • returns String

      Example

      {{resolve "docs/toc.md"}}
      
      

      {segments}

      Get specific (joined) segments of a file path by passing a range of array indices.

      Params

      • filepath String: The file path to split into segments.
      • returns String: Returns a single, joined file path.

      Example

      {{segments "a/b/c/d" "2" "3"}}
      
      
      {{segments "a/b/c/d" "1" "3"}}
      
      
      {{segments "a/b/c/d" "1" "2"}}
      
      

      regex

      {toRegex}

      Convert the given string to a regular expression.

      Params

      • str String
      • returns RegExp

      Example

      {{toRegex "foo"}}
      
      

      {test}

      Returns true if the given str matches the given regex. A regex can be passed on the context, or using the toRegex helper as a subexpression.

      Params

      • str String
      • returns RegExp

      Example

      {{test "bar" (toRegex "foo")}}
      
      {{test "foobar" (toRegex "foo")}}
      
      {{test "foobar" (toRegex "^foo$")}}
      
      

      string

      {append}

      Append the specified suffix to the given string.

      Params

      • str String
      • suffix String
      • returns String

      Example

      
      {{append item.stem ".html"}}
      
      

      {camelcase}

      camelCase the characters in the given string.

      Params

      • string String: The string to camelcase.
      • returns String

      Example

      {{camelcase "foo bar baz"}};
      
      

      {capitalize}

      Capitalize the first word in a sentence.

      Params

      • str String
      • returns String

      Example

      {{capitalize "foo bar baz"}}
      
      

      {capitalizeAll}

      Capitalize all words in a string.

      Params

      • str String
      • returns String

      Example

      {{capitalizeAll "foo bar baz"}}
      
      

      {center}

      Center a string using non-breaking spaces

      Params

      • str String
      • spaces String
      • returns String

      {chop}

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

      Params

      • string String: The string to chop.
      • returns String

      Example

      {{chop "_ABC_"}}
      
      
      {{chop "-ABC-"}}
      
      
      {{chop " ABC "}}
      
      

      {dashcase}

      dash-case the characters in string. Replaces non-word characters and periods with hyphens.

      Params

      • string String
      • returns String

      Example

      {{dashcase "a-b-c d_e"}}
      
      

      {dotcase}

      dot.case the characters in string.

      Params

      • string String
      • returns String

      Example

      {{dotcase "a-b-c d_e"}}
      
      

      {downcase}

      Lowercase all of the characters in the given string. Alias for lowercase.

      Params

      • string String
      • returns String

      Example

      {{downcase "aBcDeF"}}
      
      

      {ellipsis}

      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

      {{ellipsis (sanitize "<span>foo bar bazspan>"), 7}}
      
      {{ellipsis "foo bar baz", 7}}
      
      

      {hyphenate}

      Replace spaces in a string with hyphens.

      Params

      • str String
      • returns String

      Example

      {{hyphenate "foo bar baz qux"}}
      
      

      {isString}

      Return true if value is a string.

      Params

      • value String
      • returns Boolean

      Example

      {{isString "foo"}}
      
      

      {lowercase}

      Lowercase all characters in the given string.

      Params

      • str String
      • returns String

      Example

      {{lowercase "Foo BAR baZ"}}
      
      

      {occurrences}

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

      Params

      • str String
      • substring String
      • returns Number: Number of occurrences

      Example

      {{occurrences "foo bar foo bar baz" "foo"}}
      
      

      {pascalcase}

      PascalCase the characters in string.

      Params

      • string String
      • returns String

      Example

      {{pascalcase "foo bar baz"}}
      
      

      {pathcase}

      path/case the characters in string.

      Params

      • string String
      • returns String

      Example

      {{pathcase "a-b-c d_e"}}
      
      

      {plusify}

      Replace spaces in the given string with pluses.

      Params

      • str String: The input string
      • returns String: Input string with spaces replaced by plus signs

      Example

      {{plusify "foo bar baz"}}
      
      

      {prepend}

      Prepends the given string with the specified prefix.

      Params

      • str String
      • prefix String
      • returns String

      Example

      
      {{prepend val "foo-"}}
      
      

      {raw}

      Render a block without processing mustache templates inside the block.

      Params

      • options Object
      • returns String

      Example

      {{{{#raw}}}}
      {{foo}}
      {{{{/raw}}}}
      
      

      {remove}

      Remove all occurrences of substring from the given str.

      Params

      • str String
      • substring String
      • returns String

      Example

      {{remove "a b a b a b" "a "}}
      
      

      {removeFirst}

      Remove the first occurrence of substring from the given str.

      Params

      • str String
      • substring String
      • returns String

      Example

      {{remove "a b a b a b" "a"}}
      
      

      {replace}

      Replace all occurrences of substring a with substring b.

      Params

      • str String
      • a String
      • b String
      • returns String

      Example

      {{replace "a b a b a b" "a" "z"}}
      
      

      {replaceFirst}

      Replace the first occurrence of substring a with substring b.

      Params

      • str String
      • a String
      • b String
      • returns String

      Example

      {{replace "a b a b a b" "a" "z"}}
      
      

      {reverse}

      Reverse a string.

      Params

      • str String
      • returns String

      Example

      {{reverse "abcde"}}
      
      

      {sentence}

      Sentence case the given string

      Params

      • str String
      • returns String

      Example

      {{sentence "hello world. goodbye world."}}
      
      

      {snakecase}

      snake_case the characters in the given string.

      Params

      • string String
      • returns String

      Example

      {{snakecase "a-b-c d_e"}}
      
      

      {split}

      Split string by the given character.

      Params

      • string String: The string to split.
      • returns String character: Default is an empty string.

      Example

      {{split "a,b,c" ","}}
      
      

      {startsWith}

      Tests whether a string begins with the given prefix.

      Params

      • prefix String
      • testString String
      • options String
      • returns String

      Example

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

      {titleize}

      Title case the given string.

      Params

      • str String
      • returns String

      Example

      {{titleize "this is title case"}}
      
      

      {trim}

      Removes extraneous whitespace from the beginning and end of a string.

      Params

      • string String: The string to trim.
      • returns String

      Example

      {{trim " ABC "}}
      
      

      {trimLeft}

      Removes extraneous whitespace from the beginning of a string.

      Params

      • string String: The string to trim.
      • returns String

      Example

      {{trim " ABC "}}
      
      

      {trimRight}

      Removes extraneous whitespace from the end of a string.

      Params

      • string String: The string to trim.
      • returns String

      Example

      {{trimRight " ABC "}}
      
      

      {truncate}

      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

      truncate("foo bar baz", 7);
      
      truncate(sanitize("<span>foo bar bazspan>", 7));
      
      

      {truncateWords}

      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

      truncateWords("foo bar baz", 1);
      
      truncateWords("foo bar baz", 2);
      
      truncateWords("foo bar baz", 3);
      
      

      {upcase}

      Uppercase all of the characters in the given string. Alias for uppercase.

      Params

      • string String
      • returns String

      Example

      {{upcase "aBcDeF"}}
      
      

      {uppercase}

      Uppercase all of the characters in the given string. If used as a block helper it will uppercase the entire block. This helper does not support inverse blocks.

      Params

      • str String: The string to uppercase
      • options Object: Handlebars options object
      • returns String

      Example

      {{uppercase "aBcDeF"}}
      
      

      url

      {encodeURI}

      Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character.

      Params

      • str String: The un-encoded string
      • returns String: The endcoded string

      {escape}

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

      Params

      • str String
      • returns String: Escaped string.

      {decodeURI}

      Decode a Uniform Resource Identifier (URI) component.

      Params

      • str String
      • returns String

      {url_encode}

      Alias for encodeURI.

      {url_decode}

      Alias for decodeURI.

      {urlResolve}

      Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag.

      Params

      • base String
      • href String
      • returns String

      {urlParse}

      Parses a url string into an object.

      Params

      • str String: URL string
      • returns String: Returns stringified JSON

      {stripQuerystring}

      Strip the query string from the given url.

      Params

      • url String
      • returns String: the url without the queryString

      {stripProtocol}

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

      Params

      • str String
      • returns String: the url with http protocol stripped

      Example

      
      {{stripProtocol url}}
      
      

      Utils

      The following utils are exposed on .utils.

      {changecase}

      Change casing on the given string, optionally passing a delimiter to use between words in the returned string.

      Params

      • string String: The string to change.
      • returns String

      Example

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

      {random}

      Generate a random number

      Params

      • min Number
      • max Number
      • returns Number

      How to Contribute

      clone the repository locally and run 'npm i' in the root. Now that you've set up your workspace, you're ready to contribute changes to the fumanchu repository you can refer to the CONTRIBUTING guide. If you have any questions please feel free to ask by creating an issue and label it question.

      To test the legacy helpers, you can run npm run test:legacy to run the tests. If you want to test the new helpers, you can run npm run test.

      MIT and codebase after 2023 will be copyright of Jared Wray.

      This is a fork of handlebars-helpers which is licensed under MIT. Initial copyright of handlebars-helpers: 2013-2015, 2017, Jon Schlinkert, Brian Woodward. Thank you so much for your effort and building this! We have also continued to list all contributors in package.json to ensure that they are recognized.

      Table of Contents