1 | import { inspect } from 'util'; |
||
2 | import { isEmpty } from 'myrmidon'; |
||
3 | import handleBars from 'handlebars'; |
||
4 | import { DEFAULT_JSON_OFFSET } from './constants'; |
||
5 | |||
6 | |||
7 | handleBars.registerHelper('json', (data) => { |
||
8 | const text = Buffer.isBuffer(data) |
||
0 ignored issues
–
show
|
|||
9 | ? inspect(data) |
||
10 | : JSON.stringify(data, null, DEFAULT_JSON_OFFSET); |
||
11 | |||
12 | return new handleBars.SafeString(text); |
||
13 | }); |
||
14 | |||
15 | handleBars.registerHelper('inspect', (data, options) => { |
||
16 | const text = inspect(data, options); |
||
17 | |||
18 | return new handleBars.SafeString(text); |
||
19 | }); |
||
20 | |||
21 | handleBars.registerHelper('ident', (multiLine, offset) => { |
||
22 | const shift = Array.from({ length: offset }).map(() => ' ').join(''); |
||
23 | const changed = multiLine.toString().replace(/\n/g, `\n${shift}`); |
||
24 | |||
25 | return new handleBars.SafeString(changed); |
||
26 | }); |
||
27 | |||
28 | handleBars.registerHelper('findById', (map, id) => { |
||
29 | return map.get(id); |
||
30 | }); |
||
31 | |||
32 | |||
33 | handleBars.registerHelper({ |
||
34 | // eq : (v1, v2) => v1 === v2, |
||
35 | // ne : (v1, v2) => v1 !== v2, |
||
36 | // lt : (v1, v2) => v1 < v2, |
||
37 | // gt : (v1, v2) => v1 > v2, |
||
38 | // lte : (v1, v2) => v1 <= v2, |
||
39 | // gte : (v1, v2) => v1 >= v2, |
||
40 | // and() { |
||
41 | // return Array.prototype.every.call(arguments, Boolean); |
||
42 | // }, |
||
43 | // or() { |
||
44 | // return Array.prototype.slice.call(arguments, 0, -1).some(Boolean); |
||
45 | // }, |
||
46 | // isEmpty : v => isEmpty(v), |
||
47 | notEmpty : v => v && !isEmpty(v) |
||
48 | }); |
||
49 | |||
50 | export default handleBars; |
||
51 | |||
52 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.