mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
957 B
38 lines
957 B
9 years ago
|
var isObjectLike = require('./isObjectLike');
|
||
10 years ago
|
|
||
|
/** `Object#toString` result references. */
|
||
|
var errorTag = '[object Error]';
|
||
|
|
||
9 years ago
|
/** Used for built-in method references. */
|
||
10 years ago
|
var objectProto = Object.prototype;
|
||
|
|
||
|
/**
|
||
9 years ago
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
|
||
10 years ago
|
* of values.
|
||
|
*/
|
||
9 years ago
|
var objectToString = objectProto.toString;
|
||
10 years ago
|
|
||
|
/**
|
||
|
* Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
|
||
|
* `SyntaxError`, `TypeError`, or `URIError` object.
|
||
|
*
|
||
|
* @static
|
||
|
* @memberOf _
|
||
|
* @category Lang
|
||
|
* @param {*} value The value to check.
|
||
|
* @returns {boolean} Returns `true` if `value` is an error object, else `false`.
|
||
|
* @example
|
||
|
*
|
||
|
* _.isError(new Error);
|
||
|
* // => true
|
||
|
*
|
||
|
* _.isError(Error);
|
||
|
* // => false
|
||
|
*/
|
||
|
function isError(value) {
|
||
9 years ago
|
return isObjectLike(value) &&
|
||
|
typeof value.message == 'string' && objectToString.call(value) == errorTag;
|
||
10 years ago
|
}
|
||
|
|
||
|
module.exports = isError;
|