Last change
on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
961 bytes
|
Line | |
---|
1 | var baseGetTag = require('./_baseGetTag'),
|
---|
2 | isObjectLike = require('./isObjectLike'),
|
---|
3 | isPlainObject = require('./isPlainObject');
|
---|
4 |
|
---|
5 | /** `Object#toString` result references. */
|
---|
6 | var domExcTag = '[object DOMException]',
|
---|
7 | errorTag = '[object Error]';
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
|
---|
11 | * `SyntaxError`, `TypeError`, or `URIError` object.
|
---|
12 | *
|
---|
13 | * @static
|
---|
14 | * @memberOf _
|
---|
15 | * @since 3.0.0
|
---|
16 | * @category Lang
|
---|
17 | * @param {*} value The value to check.
|
---|
18 | * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
|
---|
19 | * @example
|
---|
20 | *
|
---|
21 | * _.isError(new Error);
|
---|
22 | * // => true
|
---|
23 | *
|
---|
24 | * _.isError(Error);
|
---|
25 | * // => false
|
---|
26 | */
|
---|
27 | function isError(value) {
|
---|
28 | if (!isObjectLike(value)) {
|
---|
29 | return false;
|
---|
30 | }
|
---|
31 | var tag = baseGetTag(value);
|
---|
32 | return tag == errorTag || tag == domExcTag ||
|
---|
33 | (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
|
---|
34 | }
|
---|
35 |
|
---|
36 | module.exports = isError;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.