Skip to content

Instantly share code, notes, and snippets.

@SeanJM
Forked from FrankFang/math.js
Last active November 14, 2017 19:58
Show Gist options
  • Save SeanJM/90044547492f700b17cfb5a0097b3023 to your computer and use it in GitHub Desktop.
Save SeanJM/90044547492f700b17cfb5a0097b3023 to your computer and use it in GitHub Desktop.
Handlebars Math.
const handlebars = require("handlebars");
const operators = {
"+": (a, b) => a + b,
"-": (a, b) => a - b,
"*": (a, b) => a * b,
"/": (a, b) => a / b,
"%": (a, b) => a % b
};
handlebars.registerHelper("math", function (a, op, b) {
return operators[op](parseFloat(a), parseFloat(b));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment