forked from helpers/handlebars-helpers
-
Notifications
You must be signed in to change notification settings - Fork 5
/
misc.js
67 lines (62 loc) · 1.34 KB
/
misc.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const crypto = require('crypto');
const utils = require('./utils');
/**
* @exports misc
*/
const helpers = module.exports;
/**
* Return the given value of `prop` from `this.options`.
*
* ```handlebars
* <!-- context = {options: {a: {b: {c: 'ddd'}}}} -->
* {{option "a.b.c"}}
* <!-- results => `ddd` -->
* ```
* @param {String} `prop`
* @return {any}
* @api public
*/
helpers.option = function(prop, locals, options) {
return utils.get(utils.options(this, locals, options), prop);
};
/**
* Block helper that renders the block without taking any arguments.
*
* @param {Object} `options`
* @return {String}
* @block
* @api public
*/
helpers.noop = function(options) {
return options.fn(this);
};
/**
* Get the native type of the given `value`
*
* ```handlebars
* {{typeOf 1}}
* //=> 'number'
* {{typeOf "1"}}
* //=> 'string'
* {{typeOf "foo"}}
* //=> 'string'
* ```
* @param {any} `value`
* @return {String} Returns the type of value.
* @api public
*/
helpers.typeOf = val => typeof val;
/**
* Get the MD5 hash of a piece of data
*
* ```handlebars
* {{md5 data}}
* //=> '527bd5b5d689e2c32ae974c6229ff785'
* ```
* @param {any} data - the data to hash
* @return {String} - The MD5 hash of the data
* @api public
*/
helpers.md5 = function(data) {
return data ? crypto.createHash('md5').update(`${data}`).digest('hex') : '';
};