1 // NOTE: These type checking functions intentionally don't use `instanceof`
2 // because it is fragile and can be easily faked with `Object.create()`.
4 return Array.isArray(ar);
6 exports.isArray = isArray;
8 function isBoolean(arg) {
9 return typeof arg === 'boolean';
11 exports.isBoolean = isBoolean;
13 function isNull(arg) {
16 exports.isNull = isNull;
18 function isNullOrUndefined(arg) {
21 exports.isNullOrUndefined = isNullOrUndefined;
23 function isNumber(arg) {
24 return typeof arg === 'number';
26 exports.isNumber = isNumber;
28 function isString(arg) {
29 return typeof arg === 'string';
31 exports.isString = isString;
33 function isSymbol(arg) {
34 return typeof arg === 'symbol';
36 exports.isSymbol = isSymbol;
38 function isUndefined(arg) {
39 return arg === void 0;
41 exports.isUndefined = isUndefined;
43 function isRegExp(re) {
44 return isObject(re) && objectToString(re) === '[object RegExp]';
46 exports.isRegExp = isRegExp;
48 function isObject(arg) {
49 return typeof arg === 'object' && arg !== null;
51 exports.isObject = isObject;
54 return isObject(d) && objectToString(d) === '[object Date]';
56 exports.isDate = isDate;
60 (objectToString(e) === '[object Error]' || e instanceof Error);
62 exports.isError = isError;
64 function isFunction(arg) {
65 return typeof arg === 'function';
67 exports.isFunction = isFunction;
69 function isPrimitive(arg) {
70 return arg === null ||
71 typeof arg === 'boolean' ||
72 typeof arg === 'number' ||
73 typeof arg === 'string' ||
74 typeof arg === 'symbol' || // ES6 symbol
75 typeof arg === 'undefined';
77 exports.isPrimitive = isPrimitive;
79 function isBuffer(arg) {
80 return Buffer.isBuffer(arg);
82 exports.isBuffer = isBuffer;
84 function objectToString(o) {
85 return Object.prototype.toString.call(o);