-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
51 lines (51 loc) · 1.07 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
var utils = {
isFunction: function(f) {
return typeof f == 'function';
},
isArray: function(a) {
return a instanceof Array;
},
isString: function(s) {
return typeof s == 'string';
},
isNumber: function(n) {
return typeof n == 'number';
},
isObject: function(o) {
return !utils.isArray(a) && typeof o == 'object';
},
isPassedByRef: function(o) {
return typeof o == 'object';
},
extend: function(o, extend) {
Object.keys(extend).forEach(function(key) {
o[key] = extend[key];
});
return o;
},
defaults: function(o, defaults) {
Object.keys(defaults).forEach(function(key) {
if (!(key in o))
o[key] = defaults[key];
});
return o;
},
normalizeToArray: function(valueOrArray) {
return utils.isArray(valueOrArray) ? valueOrArray : [valueOrArray];
},
arraysEqual: function(a, b) {
if (!utils.isArray(a) || !utils.isArray(b))
return false;
if (a.length != b.length)
return false;
if (a === b)
return true;
for (var i = 0; i < a.length; ++i)
{
if (a[i] !== b[i])
return false
}
return true;
}
};
module.exports = utils;