-
Notifications
You must be signed in to change notification settings - Fork 20
/
H.js
43 lines (36 loc) · 1.12 KB
/
H.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
// Utils
import { isObject } from './util/utils';
// Helpers
import * as html from './helpers/html';
import * as math from './helpers/math';
import * as strings from './helpers/strings';
import * as datetime from './helpers/datetime';
import * as formatters from './helpers/formatters';
import * as conditionals from './helpers/conditionals';
/**
* Class for just-handlebars-helpers.
*/
class H {
/**
* Static method to register just-handlebars-helpers with Handlebars.
*
* @param {*} handlebars
*/
static registerHelpers(handlebars) {
handlebars = handlebars || global.Handlebars;
if (!isObject(handlebars)) {
// In case, handlebars is not provided and it's not available
// in the global namespace as well throw the error and halt.
throw new Error('Handlebars not loaded');
}
// Helpers list
const helpers = [math, html, strings, conditionals, datetime, formatters];
helpers.forEach(helper => {
// Register all the helper functions to Handlebars
for (const name in helper) {
handlebars.registerHelper(name, helper[name]);
}
});
}
}
export default H;