1 | /** |
---|
2 | * Check if given obj just a primitive type wrapper |
---|
3 | * @param {Object} obj |
---|
4 | * @returns {boolean} |
---|
5 | * @api private |
---|
6 | */ |
---|
7 | exports.isWrapperType = function(obj) { |
---|
8 | return isNumber(obj) || isString(obj) || isBoolean(obj); |
---|
9 | } |
---|
10 | |
---|
11 | /** |
---|
12 | * Merge object b with object a. |
---|
13 | * |
---|
14 | * var a = { foo: 'bar' } |
---|
15 | * , b = { bar: 'baz' }; |
---|
16 | * |
---|
17 | * utils.merge(a, b); |
---|
18 | * // => { foo: 'bar', bar: 'baz' } |
---|
19 | * |
---|
20 | * @param {Object} a |
---|
21 | * @param {Object} b |
---|
22 | * @return {Object} |
---|
23 | * @api private |
---|
24 | */ |
---|
25 | |
---|
26 | exports.merge = function(a, b){ |
---|
27 | if (a && b) { |
---|
28 | for (var key in b) { |
---|
29 | a[key] = b[key]; |
---|
30 | } |
---|
31 | } |
---|
32 | return a; |
---|
33 | }; |
---|
34 | |
---|
35 | function isNumber(arg) { |
---|
36 | return typeof arg === 'number' || arg instanceof Number; |
---|
37 | } |
---|
38 | |
---|
39 | exports.isNumber = isNumber; |
---|
40 | |
---|
41 | function isString(arg) { |
---|
42 | return typeof arg === 'string' || arg instanceof String; |
---|
43 | } |
---|
44 | |
---|
45 | function isBoolean(arg) { |
---|
46 | return typeof arg === 'boolean' || arg instanceof Boolean; |
---|
47 | } |
---|
48 | exports.isBoolean = isBoolean; |
---|
49 | |
---|
50 | exports.isString = isString; |
---|
51 | |
---|
52 | function isBuffer(arg) { |
---|
53 | return typeof Buffer !== 'undefined' && arg instanceof Buffer; |
---|
54 | } |
---|
55 | |
---|
56 | exports.isBuffer = isBuffer; |
---|
57 | |
---|
58 | function isDate(d) { |
---|
59 | return isObject(d) && objectToString(d) === '[object Date]'; |
---|
60 | } |
---|
61 | |
---|
62 | exports.isDate = isDate; |
---|
63 | |
---|
64 | function objectToString(o) { |
---|
65 | return Object.prototype.toString.call(o); |
---|
66 | } |
---|
67 | |
---|
68 | function isObject(arg) { |
---|
69 | return typeof arg === 'object' && arg !== null; |
---|
70 | } |
---|
71 | |
---|
72 | exports.isObject = isObject; |
---|
73 | |
---|
74 | function isRegExp(re) { |
---|
75 | return isObject(re) && objectToString(re) === '[object RegExp]'; |
---|
76 | } |
---|
77 | |
---|
78 | exports.isRegExp = isRegExp; |
---|
79 | |
---|
80 | function isNullOrUndefined(arg) { |
---|
81 | return arg == null; |
---|
82 | } |
---|
83 | |
---|
84 | exports.isNullOrUndefined = isNullOrUndefined; |
---|
85 | |
---|
86 | function isArguments(object) { |
---|
87 | return objectToString(object) === '[object Arguments]'; |
---|
88 | } |
---|
89 | |
---|
90 | exports.isArguments = isArguments; |
---|
91 | |
---|
92 | exports.isFunction = function(arg) { |
---|
93 | return typeof arg === 'function' || arg instanceof Function; |
---|
94 | }; |
---|
95 | |
---|
96 | function isError(e) { |
---|
97 | return isObject(e) && objectToString(e) === '[object Error]'; |
---|
98 | } |
---|
99 | exports.isError = isError; |
---|