-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
62 lines (51 loc) · 1.05 KB
/
utils.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
'use strict';
var utils = require('lazy-cache')(require);
var fn = require;
require = utils;
/**
* Lazily required module dependencies
*/
require('engine-cache', 'Engines');
require('define-property', 'define');
require('is-valid-app', 'isValid');
require = fn;
/**
* Arrayify the given value by casting it to an array.
*/
utils.arrayify = function(val) {
return val ? (Array.isArray(val) ? val : [val]) : [];
};
/**
* Return true if the given value is a string.
*/
utils.isString = function(val) {
return val && typeof val === 'string';
};
/**
* Ensure file extensions are formatted properly for lookups.
*
* ```js
* utils.formatExt('hbs');
* //=> '.hbs'
*
* utils.formatExt('.hbs');
* //=> '.hbs'
* ```
*
* @param {String} `ext` File extension
* @return {String}
* @api public
*/
utils.formatExt = function formatExt(ext) {
if (typeof ext !== 'string') {
throw new Error('expected a string');
}
if (ext.charAt(0) !== '.') {
return '.' + ext;
}
return ext;
};
/**
* Expose `utils` modules
*/
module.exports = utils;