-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
34 lines (32 loc) · 810 Bytes
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const HELPERS = {
for: function(n, block) {
var accum = "";
for (var i = 1; i <= n; i++) {
accum += block.fn(i);
}
return accum;
},
formatDate: function(date) {
if (!date) {
return "";
}
return ` ${
date.getDate() < 10 ? "0" + date.getDate() : date.getDate()
}-${date.getMonth() + 1}-${date.getFullYear()}`;
},
ifEquals: function(arg1, arg2, options) {
return arg1 == arg2 ? options.fn(this) : options.inverse(this);
},
math: function(lvalue, operator, rvalue, options) {
lvalue = parseFloat(lvalue);
rvalue = parseFloat(rvalue);
return {
"+": lvalue + rvalue,
"-": lvalue - rvalue,
"*": lvalue * rvalue,
"/": lvalue / rvalue,
"%": lvalue % rvalue
}[operator];
}
};
module.exports = HELPERS;