source: Dev/trunk/node_modules/should/lib/util.js @ 484

Last change on this file since 484 was 484, checked in by hendrikvanantwerpen, 11 years ago

Commit node_modules, to make checkouts and builds more deterministic.

File size: 1.9 KB
Line 
1/**
2 * Check if given obj just a primitive type wrapper
3 * @param {Object} obj
4 * @returns {boolean}
5 * @api private
6 */
7exports.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
26exports.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
35function isNumber(arg) {
36  return typeof arg === 'number' || arg instanceof Number;
37}
38
39exports.isNumber = isNumber;
40
41function isString(arg) {
42  return typeof arg === 'string' || arg instanceof String;
43}
44
45function isBoolean(arg) {
46  return typeof arg === 'boolean' || arg instanceof Boolean;
47}
48exports.isBoolean = isBoolean;
49
50exports.isString = isString;
51
52function isBuffer(arg) {
53  return typeof Buffer !== 'undefined' && arg instanceof Buffer;
54}
55
56exports.isBuffer = isBuffer;
57
58function isDate(d) {
59  return isObject(d) && objectToString(d) === '[object Date]';
60}
61
62exports.isDate = isDate;
63
64function objectToString(o) {
65  return Object.prototype.toString.call(o);
66}
67
68function isObject(arg) {
69  return typeof arg === 'object' && arg !== null;
70}
71
72exports.isObject = isObject;
73
74function isRegExp(re) {
75  return isObject(re) && objectToString(re) === '[object RegExp]';
76}
77
78exports.isRegExp = isRegExp;
79
80function isNullOrUndefined(arg) {
81  return arg == null;
82}
83
84exports.isNullOrUndefined = isNullOrUndefined;
85
86function isArguments(object) {
87  return objectToString(object) === '[object Arguments]';
88}
89
90exports.isArguments = isArguments;
91
92exports.isFunction = function(arg) {
93  return typeof arg === 'function' || arg instanceof Function;
94};
95
96function isError(e) {
97  return isObject(e) && objectToString(e) === '[object Error]';
98}
99exports.isError = isError;
Note: See TracBrowser for help on using the repository browser.