1 | 'use strict';
|
2 |
|
3 | const _ = require('lodash');
|
4 | const helpers = require('handlebars-helpers');
|
5 | const whitelist = [
|
6 | {
|
7 | name: 'array',
|
8 | include: [
|
9 | 'after',
|
10 | 'arrayify',
|
11 | 'before',
|
12 | 'eachIndex',
|
13 | 'filter',
|
14 | 'first',
|
15 | 'forEach',
|
16 | 'inArray',
|
17 | 'isArray',
|
18 | 'last',
|
19 | 'lengthEqual',
|
20 | 'map',
|
21 | 'some',
|
22 | 'sort',
|
23 | 'sortBy',
|
24 | 'withAfter',
|
25 | 'withBefore',
|
26 | 'withFirst',
|
27 | 'withLast',
|
28 | 'withSort',
|
29 | ],
|
30 | },
|
31 | {
|
32 | name: 'collection',
|
33 | include: ['isEmpty', 'iterate', 'length'],
|
34 | },
|
35 | {
|
36 | name: 'comparison',
|
37 | include: [
|
38 | 'and',
|
39 | 'gt',
|
40 | 'gte',
|
41 | 'has',
|
42 | 'eq',
|
43 | 'ifEven',
|
44 | 'ifNth',
|
45 | 'ifOdd',
|
46 | 'is',
|
47 | 'isnt',
|
48 | 'lt',
|
49 | 'lte',
|
50 | 'neither',
|
51 | 'unlessEq',
|
52 | 'unlessGt',
|
53 | 'unlessLt',
|
54 | 'unlessGteq',
|
55 | 'unlessLteq',
|
56 | ],
|
57 | },
|
58 | {
|
59 | name: 'date',
|
60 | include: ['moment'],
|
61 | },
|
62 | {
|
63 | name: 'html',
|
64 | include: ['ellipsis', 'sanitize', 'ul', 'ol', 'thumbnailImage']
|
65 | },
|
66 | {
|
67 | name: 'inflection',
|
68 | include: ['inflect', 'ordinalize'],
|
69 | },
|
70 | {
|
71 | name: 'markdown',
|
72 | include: ['markdown'],
|
73 | },
|
74 | {
|
75 | name: 'math',
|
76 | include: ['add', 'subtract', 'divide', 'multiply', 'floor', 'ceil', 'round', 'sum', 'avg'],
|
77 | },
|
78 | {
|
79 | name: 'misc',
|
80 | include: ['default', 'option', 'noop', 'withHash'],
|
81 | },
|
82 | {
|
83 | name: 'number',
|
84 | include: [
|
85 | 'addCommas',
|
86 | 'phoneNumber',
|
87 | 'random',
|
88 | 'toAbbr',
|
89 | 'toExponential',
|
90 | 'toFixed',
|
91 | 'toFloat',
|
92 | 'toInt',
|
93 | 'toPrecision',
|
94 | ],
|
95 | },
|
96 | {
|
97 | name: 'object',
|
98 | include: [
|
99 | 'extend',
|
100 | 'forIn',
|
101 | 'forOwn',
|
102 | 'toPath',
|
103 | 'get',
|
104 | 'getObject',
|
105 | 'hasOwn',
|
106 | 'isObject',
|
107 | 'merge',
|
108 | 'JSONparse',
|
109 | 'JSONstringify',
|
110 | ],
|
111 | },
|
112 | {
|
113 | name: 'string',
|
114 | include: [
|
115 | 'camelcase',
|
116 | 'capitalize',
|
117 | 'capitalizeAll',
|
118 | 'center',
|
119 | 'chop',
|
120 | 'dashcase',
|
121 | 'dotcase',
|
122 | 'hyphenate',
|
123 | 'isString',
|
124 | 'lowercase',
|
125 | 'occurrences',
|
126 | 'pascalcase',
|
127 | 'pathcase',
|
128 | 'plusify',
|
129 | 'reverse',
|
130 | 'sentence',
|
131 | 'snakecase',
|
132 | 'split',
|
133 | 'startsWith',
|
134 | 'titleize',
|
135 | 'trim',
|
136 | 'uppercase'
|
137 | ],
|
138 | },
|
139 | {
|
140 | name: 'url',
|
141 | include: ['encodeURI', 'decodeURI', 'urlResolve', 'urlParse', 'stripQuerystring', 'stripProtocol'],
|
142 | },
|
143 | ];
|
144 |
|
145 | function helper(paper) {
|
146 | whitelist.forEach(helper => paper.handlebars.registerHelper(_.pick(helpers[helper.name](), helper.include)));
|
147 | }
|
148 |
|
149 | module.exports = helper;
|