Implement _.isError

This commit is contained in:
Mike Pennisi
2014-04-18 20:38:31 -04:00
committed by John-David Dalton
parent 976e81be43
commit b018ada5c8
2 changed files with 74 additions and 3 deletions

View File

@@ -6531,6 +6531,28 @@
return typeof value == 'undefined';
}
/**
* Checks if `value` is an instance of a native `Error` class.
*
* @static
* @memberOf _
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an instance of a native `Error`, else `false`.
* @example
*
* _.isError(new Error);
* // => true
*
* _.isError('string');
* // => false
*/
function isError(value) {
var type = typeof value;
return value && type == 'object' && toString.call(value) == errorClass ||
false;
}
/**
* Creates an array of the own enumerable property names of `object`.
*
@@ -8376,6 +8398,7 @@
lodash.isRegExp = isRegExp;
lodash.isString = isString;
lodash.isUndefined = isUndefined;
lodash.isError = isError;
lodash.kebabCase = kebabCase;
lodash.lastIndexOf = lastIndexOf;
lodash.mixin = mixin;