String Helpers
Table of Contents
- string
- {append}
- {camelcase}
- {capitalize}
- {capitalizeAll}
- {center}
- {chop}
- {dashcase}
- {dotcase}
- {downcase}
- {ellipsis}
- {hyphenate}
- {isString}
- {lowercase}
- {occurrences}
- {pascalcase}
- {pathcase}
- {plusify}
- {prepend}
- {raw}
- {remove}
- {removeFirst}
- {replace}
- {replaceFirst}
- {reverse}
- {sentence}
- {snakecase}
- {split}
- {startsWith}
- {titleize}
- {trim}
- {trimLeft}
- {trimRight}
- {truncate}
- {truncateWords}
- {upcase}
- {uppercase}
string
Visit the: code | unit tests
{append}
Append the specified suffix
to the given string.
Params
str
Stringsuffix
Stringreturns
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
Stringreturns
String
Example
{{capitalize "foo bar baz"}}
{capitalizeAll}
Capitalize all words in a string.
Params
str
Stringreturns
String
Example
{{capitalizeAll "foo bar baz"}}
{center}
Center a string using non-breaking spaces
Params
str
Stringspaces
Stringreturns
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
Stringreturns
String
Example
{{dashcase "a-b-c d_e"}}
{dotcase}
dot.case the characters in string
.
Params
string
Stringreturns
String
Example
{{dotcase "a-b-c d_e"}}
{downcase}
Lowercase all of the characters in the given string. Alias for lowercase.
Params
string
Stringreturns
String
Example
{{downcase "aBcDeF"}}
{ellipsis}
Truncates a string to the specified length
, and appends it with an elipsis, …
.
Params
str
Stringlength
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
Stringreturns
String
Example
{{hyphenate "foo bar baz qux"}}
{isString}
Return true if value
is a string.
Params
value
Stringreturns
Boolean
Example
{{isString "foo"}}
{lowercase}
Lowercase all characters in the given string.
Params
str
Stringreturns
String
Example
{{lowercase "Foo BAR baZ"}}
{occurrences}
Return the number of occurrences of substring
within the given string
.
Params
str
Stringsubstring
Stringreturns
Number: Number of occurrences
Example
{{occurrences "foo bar foo bar baz" "foo"}}
{pascalcase}
PascalCase the characters in string
.
Params
string
Stringreturns
String
Example
{{pascalcase "foo bar baz"}}
{pathcase}
path/case the characters in string
.
Params
string
Stringreturns
String
Example
{{pathcase "a-b-c d_e"}}
{plusify}
Replace spaces in the given string with pluses.
Params
str
String: The input stringreturns
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
Stringprefix
Stringreturns
String
Example
{{prepend val "foo-"}}
{raw}
Render a block without processing mustache templates inside the block.
Params
options
Objectreturns
String
Example
{{{{#raw}}}}
{{foo}}
{{{{/raw}}}}
{remove}
Remove all occurrences of substring
from the given str
.
Params
str
Stringsubstring
Stringreturns
String
Example
{{remove "a b a b a b" "a "}}
{removeFirst}
Remove the first occurrence of substring
from the given str
.
Params
str
Stringsubstring
Stringreturns
String
Example
{{remove "a b a b a b" "a"}}
{replace}
Replace all occurrences of substring a
with substring b
.
Params
str
Stringa
Stringb
Stringreturns
String
Example
{{replace "a b a b a b" "a" "z"}}
{replaceFirst}
Replace the first occurrence of substring a
with substring b
.
Params
str
Stringa
Stringb
Stringreturns
String
Example
{{replace "a b a b a b" "a" "z"}}
{reverse}
Reverse a string.
Params
str
Stringreturns
String
Example
{{reverse "abcde"}}
{sentence}
Sentence case the given string
Params
str
Stringreturns
String
Example
{{sentence "hello world. goodbye world."}}
{snakecase}
snake_case the characters in the given string
.
Params
string
Stringreturns
String
Example
{{snakecase "a-b-c d_e"}}
{split}
Split string
by the given character
.
Params
string
String: The string to split.returns
Stringcharacter
: Default is an empty string.
Example
{{split "a,b,c" ","}}
{startsWith}
Tests whether a string begins with the given prefix.
Params
prefix
StringtestString
Stringoptions
Stringreturns
String
Example
{{#startsWith "Goodbye" "Hello, world!"}}
Whoops
{{else}}
Bro, do you even hello world?
{{/startsWith}}
{titleize}
Title case the given string.
Params
str
Stringreturns
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
Stringlimit
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
Stringlimit
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
Stringreturns
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 uppercaseoptions
Object: Handlebars options objectreturns
String
Example
{{uppercase "aBcDeF"}}