-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
46 lines (37 loc) · 855 Bytes
/
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
'use strict';
var isObject = require('isobject');
var utils = module.exports;
/**
* Utils
*/
utils.isString = function(val) {
return val && typeof val === 'string';
};
utils.arrayify = function(val) {
return val ? (Array.isArray(val) ? val : [val]) : [];
};
utils.formatExt = function(ext) {
if (!utils.isString(ext)) return '';
if (ext.charAt(0) !== '.') {
return '.' + ext;
}
return ext;
};
utils.stripExt = function(str) {
if (!utils.isString(str)) return '';
if (str.charAt(0) === '.') {
str = str.slice(1);
}
return str;
};
utils.isEngine = function(val) {
if (typeof val === 'function') return true;
if (!isObject(val)) return false;
return val.hasOwnProperty('render')
|| val.hasOwnProperty('renderSync')
|| val.hasOwnProperty('renderFile');
};
/**
* Expose `utils`
*/
module.exports = utils;