forked from helpers/handlebars-helpers
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
40 lines (34 loc) · 1017 Bytes
/
index.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
/*!
* handlebars-helpers <https://github.com/helpers/handlebars-helpers>
*
* Copyright (c) 2013-2017, Jon Schlinkert, Brian Woodward.
* Released under the MIT License.
*/
const lib = require('./lib/');
module.exports = (groups, options) => {
if (typeof groups === 'string') {
groups = [groups];
} else if (!Array.isArray(groups)) {
options = groups;
groups = null;
}
const hbs = options.handlebars || options.hbs;
if (!hbs) throw new Error('You need to pass "handlebars" as an option');
if (groups) {
groups.forEach(function(key) {
hbs.registerHelper(lib[key]);
});
} else {
Object.keys(lib).forEach(key => hbs.registerHelper(lib[key]));
}
return hbs.helpers;
};
Object.keys(lib).forEach(key => {
module.exports[key] = options => {
options = options || {};
const hbs = options.handlebars || options.hbs;
if (!hbs) throw new Error('You need to pass "handlebars" as an option');
hbs.registerHelper(lib[key]);
return hbs.helpers;
};
});