-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathhbs_helpers.js
97 lines (83 loc) · 2.58 KB
/
hbs_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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const moment = require("moment-timezone");
const hbs = require("hbs");
const config = require("./config");
module.exports = () => {
moment.updateLocale("en", {
calendar: {
lastDay: "[Yesterday at] H:mm",
sameDay: "[Today at] H:mm",
nextDay: "[Tomorrow at] H:mm",
lastWeek: "[Last] dddd [at] H:mm",
nextWeek: "dddd [at] H:mm",
sameElse: "L",
},
});
hbs.registerHelper("asset", function (path) {
return path;
});
hbs.registerHelper("calendar", function (when) {
return moment.tz(when, config.timezone).format("ddd, MMMM Do, HH:mm");
});
hbs.registerHelper("calendarShort", function (when) {
return moment.tz(when, config.timezone).format("MMM D, HH:mm");
});
hbs.registerHelper("formatTime", (when) => {
return moment.tz(when, config.timezone).format("HH:mm");
});
hbs.registerHelper("formatDate", (when) => {
return moment.tz(when, config.timezone).format("ddd, MMMM Do");
});
hbs.registerHelper("newsDate", function (when) {
return moment.tz(when, config.timezone).calendar();
});
hbs.registerHelper("toFixed1", function (number) {
return Math.round(number * 10) / 10;
});
hbs.registerHelper("showGoals", function (goals) {
return goals === undefined || goals === null ? "-" : goals + "";
});
hbs.registerHelper("isZero", function (num) {
return num === 0 || num === "0";
});
hbs.registerHelper("gt0", function (val) {
return val > 0;
});
hbs.registerHelper("lt0", function (val) {
return val < 0;
});
hbs.registerHelper("contains", function (arr, val) {
if (arr === undefined || arr === null) {
return false;
}
return arr.includes(val);
});
hbs.registerHelper({
eq: function (v1, v2) {
return v1 === v2;
},
ne: function (v1, v2) {
return v1 !== v2;
},
lt: function (v1, v2) {
return v1 < v2;
},
gt: function (v1, v2) {
return v1 > v2;
},
lte: function (v1, v2) {
return v1 <= v2;
},
gte: function (v1, v2) {
return v1 >= v2;
},
not: function (v) {
return !v;
},
and: function () {
return Array.prototype.slice.call(arguments, 0, -1).every(Boolean);
},
or: function () {
return Array.prototype.slice.call(arguments, 0, -1).some(Boolean);
},
});
};