1 // Copyright Joyent, Inc. and other Node contributors.
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to permit
8 // persons to whom the Software is furnished to do so, subject to the
9 // following conditions:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // NOTE: These type checking functions intentionally don't use `instanceof`
23 // because it is fragile and can be easily faked with `Object.create()`.
24 function isArray(ar) {
25 return Array.isArray(ar);
27 exports.isArray = isArray;
29 function isBoolean(arg) {
30 return typeof arg === 'boolean';
32 exports.isBoolean = isBoolean;
34 function isNull(arg) {
37 exports.isNull = isNull;
39 function isNullOrUndefined(arg) {
42 exports.isNullOrUndefined = isNullOrUndefined;
44 function isNumber(arg) {
45 return typeof arg === 'number';
47 exports.isNumber = isNumber;
49 function isString(arg) {
50 return typeof arg === 'string';
52 exports.isString = isString;
54 function isSymbol(arg) {
55 return typeof arg === 'symbol';
57 exports.isSymbol = isSymbol;
59 function isUndefined(arg) {
60 return arg === void 0;
62 exports.isUndefined = isUndefined;
64 function isRegExp(re) {
65 return isObject(re) && objectToString(re) === '[object RegExp]';
67 exports.isRegExp = isRegExp;
69 function isObject(arg) {
70 return typeof arg === 'object' && arg !== null;
72 exports.isObject = isObject;
75 return isObject(d) && objectToString(d) === '[object Date]';
77 exports.isDate = isDate;
81 (objectToString(e) === '[object Error]' || e instanceof Error);
83 exports.isError = isError;
85 function isFunction(arg) {
86 return typeof arg === 'function';
88 exports.isFunction = isFunction;
90 function isPrimitive(arg) {
91 return arg === null ||
92 typeof arg === 'boolean' ||
93 typeof arg === 'number' ||
94 typeof arg === 'string' ||
95 typeof arg === 'symbol' || // ES6 symbol
96 typeof arg === 'undefined';
98 exports.isPrimitive = isPrimitive;
100 function isBuffer(arg) {
101 return Buffer.isBuffer(arg);
103 exports.isBuffer = isBuffer;
105 function objectToString(o) {
106 return Object.prototype.toString.call(o);