src/handlebars.js   A
last analyzed

Complexity

Total Complexity 7
Complexity/F 1.17

Size

Lines of Code 50
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 21
mnd 1
bc 1
fnc 6
dl 0
loc 50
rs 10
bpm 0.1666
cpm 1.1666
noi 1
c 0
b 0
f 0
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
Bug introduced by
The variable Buffer seems to be never declared. If this is a global, consider adding a /** global: Buffer */ comment.

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.

Loading history...
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