Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing redundant checks #8

Merged
merged 3 commits into from
Nov 20, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@

// NOTE: These type checking functions intentionally don't use `instanceof`
// because it is fragile and can be easily faked with `Object.create()`.
function isArray(ar) {
return Array.isArray(ar);

function isArray(arg) {
if (Array.isArray) {
return Array.isArray(arg);
}
return objectToString(arg) === '[object Array]';
}
exports.isArray = isArray;

Expand Down Expand Up @@ -62,7 +66,7 @@ function isUndefined(arg) {
exports.isUndefined = isUndefined;

function isRegExp(re) {
return isObject(re) && objectToString(re) === '[object RegExp]';
return objectToString(re) === '[object RegExp]';
}
exports.isRegExp = isRegExp;

Expand All @@ -72,13 +76,12 @@ function isObject(arg) {
exports.isObject = isObject;

function isDate(d) {
return isObject(d) && objectToString(d) === '[object Date]';
return objectToString(d) === '[object Date]';
}
exports.isDate = isDate;

function isError(e) {
return isObject(e) &&
(objectToString(e) === '[object Error]' || e instanceof Error);
return (objectToString(e) === '[object Error]' || e instanceof Error);
}
exports.isError = isError;

Expand All @@ -97,11 +100,8 @@ function isPrimitive(arg) {
}
exports.isPrimitive = isPrimitive;

function isBuffer(arg) {
return Buffer.isBuffer(arg);
}
exports.isBuffer = isBuffer;
exports.isBuffer = Buffer.isBuffer;

function objectToString(o) {
return Object.prototype.toString.call(o);
}
}