Skip to content

String helpers

camelcase

camelCase the characters in the given string.

Parameters:

  • string {String}: The string to camelcase.

Returns {String}

Example:

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

capitalize

Capitalize the first word in a sentence.

Parameters:

  • str {String}

Returns {String}

Example:

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

capitalizeAll

Capitalize all words in a string.

Parameters:

  • str {String}

Returns {String}

Example:

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

center

Center a string using non-breaking spaces

Parameters:

  • 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.

Parameters:

  • string {String}

Returns {String}

Example:

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

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

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

dashcase

Parameters:

  • string {String}

Returns {String}

Example:

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

dotcase

dot.case the characters in string.

Parameters:

  • string {String}

Returns {String}

Example:

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

hyphenate

Replace spaces in a string with hyphens.

Parameters:

  • str {String}

Returns {String}

Example:

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

isString

Return true if value is a string.

Parameters:

  • value {String}

Returns {Boolean}

Example:

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

lowercase

Lowercase all characters in the given string.

Parameters:

  • str {String}

Returns {String}

Example:

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

occurrences

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

Parameters:

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

Example:

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

pascalcase

PascalCase the characters in string.

Parameters:

  • string {String}

Returns {String}

Example:

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

pathcase

path/case the characters in string

Parameters:

  • string {String}
  • returns {String}

Example:

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

plusify

Replace spaces in the given string with pluses.

Parameters:

  • str {String}: The input string

Returns {String}: Input string with spaces replaced by plus signs

Example:

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

replace

Replace all occurrences of substring a with substring b.

Parameters:

  • str {String}
  • a {String}
  • b {String}

Returns {String}

Example:

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

reverse

Reverse a string.

Parameters:

  • str {String}

Returns {String}

Example:

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

sentence

Sentence case the given string

Parameters:

  • str {String}

Returns {String}

Example:

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

snakecase

Snake_case the characters in the given string.

Parameters:

  • string {String}

Returns {String}

Example:

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

split

Split string by the given character.

Parameters:

  • string {String}: The string to be split

Returns {String} character : Default is an empty string.

Example:

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

startsWith

Tests whether a string begins with the given prefix.

Parameters:

  • prefix {String}
  • testString {String}
  • options {String}

Returns {String}

Example:

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

titleize

  • str {String}
  • returns {String}

Example:

{{titleize "this is title case"}}
<!-- results in:  'This Is Title Case' -->

trim

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

Parameters:

  • string {String}: The string to trim.

Returns {String}

Example:

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

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.

Parameters:

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

Returns {String}

Example:

{{uppercase "aBcDeF"}}
<!-- results in:  'ABCDEF' -->