A helper for Handlebars that adds comparison functions. Meant to supercede helpers/handlebars-helpers
' comparison helpers.
const Handlebars = require('handlebars');
require('hbl-comparison').default();
const tpl = Handlebars.compile('{{#lt 2 4}}Tiny number.{{else}}Big number.{{/lt}}');
console.log(tpl()); // result : 'Tiny number.'
If both a
and b
are true, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : A
Compares a
and b
with an operator. If the result is true, the block is rendered. Otherwise, the inverse is rendered.
The operator must be a string (enclose in strings). The conventional operators are supported : >
, >=
, ==
, ===
, !=
, !==
, <=
, <
. typeof
is also supported, where a
is checked to be the typeof
b
.
Usage :
Result : B
Checks if an array contains a value. If it does, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : B
Checks if a value
is undefined. If it is, the defaultValue
is rendered — otherwise, the value
is.
Usage : {{ default apple "Whoops, I forgot to define something" }}
Result : Whoops, I forgot to define something
Checks if a === b
. If the result is true, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : A
Checks if a > b
. If the result is true, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : B
Checks if a >= b
. If the result is true, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : A
Checks if an array has a pattern. If it does, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : A
Checks if num
is even. If it is, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : A
Checks if a
is divisible by b
evenly (no remainder). If it is, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : A
Checks if num
is odd. If it is, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : B
Checks if a == b
. If it is, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : B
Checks if val
is false. If it is, the block is rendered. Otherwise, the inverse is rendered.
Usage : {{ isFalsey false }}
Result : true
Checks if a != b
. If it is, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : A
Checks if val
is true. If it is, the block is rendered. Otherwise, the inverse is rendered.
Usage : {{ isTruthy false }}
Result : false
Checks if a < b
. If the result is true, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : B
Checks if a <= b
. If the result is true, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : A
Checks if a
and b
are false. If it is, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : B
Checks if val
is false. If it is, the block is rendered. Otherwise, the inverse is rendered.
Usage : {{ not false }}
Result : true
If either a
or b
are true, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : A
Checks if a !== b
. If the result is true, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : B
Checks if a <= b
. If the result is true, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : B
Checks if a < b
. If the result is true, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : A
Checks if a >= b
. If the result is true, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : B
Checks if a > b
. If the result is true, the block is rendered. Otherwise, the inverse is rendered.
Usage :
Result : A
This package is licensed under the 3-Clause BSD licence. A copy of it can be found in the LICENSE
file in the root of the source repository and in the root of the package directory.