-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUtils.js
58 lines (50 loc) · 1.28 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
/**
* Created by codeslayer on 3/13/16.
*/
module.exports = {
/**
* This function checks for empty/null variable/object
*
* @param obj
* @return boolean
*/
isEmpty:function (obj) {
// Speed up calls to hasOwnProperty
var hasOwnProperty = Object.prototype.hasOwnProperty;
// null and undefined are "empty"
if (obj == null) return true;
// Assume if it has a length property with a non-zero value
// that that property is correct.
if (obj.length && obj.length > 0) return false;
if (obj.length === 0) return true;
if(obj.toString())
// Otherwise, does it have any properties of its own?
// Note that this doesn't handle
// toString and valueOf enumeration bugs in IE < 9
for (var key in obj) {
if (hasOwnProperty.call(obj, key)) return false;
}
if (!isNaN(obj)) {
if (obj.toString().length > 0) return false;
}
return true;
},
/**
* Function to check if the variable is an array
*
* @param a
* @return boolean
*/
isArray: function(a) {
return (!!a) && (a.constructor === Array);
},
/**
* Function to check if the variable is an object
*
* @param a
* @return boolean
*/
isObject: function(a) {
return (!!a) && (a.constructor === Object);
}
};