PageRenderTime 22ms CodeModel.GetById 19ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/lodash/isError.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 36 lines | 14 code | 3 blank | 19 comment | 8 complexity | ab9bfcb636d28e93e025d51cb42ae928 MD5 | raw file
 1var baseGetTag = require('./_baseGetTag'),
 2    isObjectLike = require('./isObjectLike'),
 3    isPlainObject = require('./isPlainObject');
 4
 5/** `Object#toString` result references. */
 6var 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 */
27function 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
36module.exports = isError;