hbl-maths
v0.1.0
Published
A handler for Handlebars that adds mathematics.
Downloads
1
Readme
hbl-maths
A set of helpers for Handlebars that adds mathematics. Meant to superseed helpers/handlebars-helpers
' maths helpers.
Usage
const Handlebars = require('handlebars');
require('hbl-maths').default();
const tpl = Handlebars.compile('{{abs x}}');
console.log(tpl({x: -5})); // result : '5'
Package documentation
{{ abs num }}
Get the absolute value of a number.
Usage : {{ abs -5 }}
Result : 5
{{ add x y }}
Calculate the sum of two numbers. Aliased as {{ plus x y }}
.
Usage : {{ add 1 2 }}
Result : 3
{{ ceil num }}
Round a number up and return the smallest integer greater than or equal to a given number.
Usage : {{ ceil 0.95 }}
Result : 1
{{ divide x y }}
Calculate the quotient of two numbers.
Usage : {{ divide 6 2 }}
Result : 3
{{ floor num }}
Round a number down and return the largest integer less than or equal to a given number.
Usage : {{ ceil 0.95 }}
Result : 1
{{ modulo x y }}
Calculate the remainder when dividing two numbers. Aliased as {{ remainder x y }}
.
Usage : {{ modulo 5 2 }}
Result : 1
{{ multiply x y }}
Calculate the product of two numbers. Aliased as {{ times x y }}
and {{ product x y }}
.
Usage : {{ multiply 5 2 }}
Result : 10
{{ random min max }}
Generate a random number between two numbers.
Usage : {{ random 0 5 }}
Result : a random number between 0 and 5
{{ round num }}
Round a number.
Usage : {{ round 4.6 }}
Result : 5
{{ subtract x y }}
Calculate the difference of two numbers. Aliased as {{ minus x y }}
.
Usage : {{ subtract 6 2 }}
Result : 4
Acknowledgements
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.