-
-
Save SeanJM/90044547492f700b17cfb5a0097b3023 to your computer and use it in GitHub Desktop.
Handlebars Math.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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