@timkendrick/handlebars-core-helpers
v0.1.5
Published
Useful helpers for Handlebars templates
Downloads
16
Readme
handlebars-core-helpers
Useful helpers for Handlebars templates
Included helpers
Logic helpers:
{{ eq value1 value2 [...valueN] }}
– Returntrue
if all arguments are strictly equal to each other, otherwise returnfalse
{{ not-eq value1 value2 [...valueN] }}
– Returntrue
if all arguments are not strictly equal to each other, otherwise returnfalse
{{ not value }}
– Returntrue
ifvalue
is empty, otherwise returnfalse
{{ and value1 value2 [...valueN] }}
– Returntrue
if all arguments are not empty, otherwise returnfalse
{{ or value1 value2 [...valueN] }}
– Returntrue
if at least one argument is not empty, otherwise returnfalse
{{ gt value1 value2 }}
– Returntrue
ifvalue1 > value2
, otherwise returnfalse
{{ gte value1 value2 }}
– Returntrue
ifvalue1 >= value2
, otherwise returnfalse
{{ lt value1 value2 }}
– Returntrue
ifvalue1 < value2
, otherwise returnfalse
{{ lte value1 value2 }}
– Returntrue
ifvalue1 <= value2
, otherwise returnfalse
Datatype helpers:
{{ is-undefined value }}
– Returntrue
ifvalue
isundefined
, otherwise returnfalse
{{ is-null value }}
– Returntrue
ifvalue
isnull
, otherwise returnfalse
{{ is-boolean value }}
– Returntrue
ifvalue
is a boolean, otherwise returnfalse
{{ is-number value }}
– Returntrue
ifvalue
is a number, otherwise returnfalse
{{ is-string value }}
– Returntrue
ifvalue
is a string, otherwise returnfalse
{{ is-object value }}
– Returntrue
ifvalue
is a non-null object, otherwise returnfalse
{{ is-symbol value }}
– Returntrue
ifvalue
is an ES6 Symbol, otherwise returnfalse
{{ is-function value }}
– Returntrue
ifvalue
is a function, otherwise returnfalse
{{ is-array value }}
– Returntrue
ifvalue
is an array, otherwise returnfalse
{{ is-date value }}
– Returntrue
ifvalue
is a Date object, otherwise returnfalse
{{ is-regexp value }}
– Returntrue
ifvalue
is a RegExp object, otherwise returnfalse
{{ is-numeric value }}
– Returntrue
ifvalue
can be coerced to a number, otherwise returnfalse
String helpers:
{{ concat value1 value2 [...valueN] separator=[separator=''] }}
– Return a concatenated string consisting of all arguments joined together byseparator
{{ replace source pattern replacement }}
– Replace first occurence ofpattern
insource
withreplacement
{{ starts-with haystack needle }}
– Returntrue
ifhaystack
starts withneedle
, otherwise returnfalse
{{ escape-newlines value }}
– Replace\n
and\r
characters invalue
with

and
HTML entities (useful to preserve formatting inwhite-space: pre
elements){{ nl2br value }}
– Replace newline characters invalue
with<br/>
HTML tags{{ wrap value left right }}
– Return an HTML-safe string consisting of an HTML-escapedvalue
wrapped between unescapedleft
andright
HTML segments{{ safe value }}
– Return an HTML-safe string representation ofvalue
Date helpers:
{{ timestamp date }}
– Return the UNIX timestamp corresponding todate
, e.g.1262304000
{{ date date }}
– [deprecated] Return a short date label corresponding todate
, e.g."Mon 1 Jan 1970"
(uses UTC time).
Serialization helpers:
{{ json value {[indent=undefined]} }}
– Return a JSON-encoded string representation ofvalue
{{ parse-json value }}
– Return the object that results from parsing thevalue
JSON string{{ urlencode value }}
– Return a URL-encoded representation ofvalue
{{ urldecode value }}
– Return a version ofvalue
with URL entities decoded