-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (43 loc) · 1.36 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*!
* is-typeof-error <https://github.com/tunnckoCore/is-typeof-error>
*
* Copyright (c) 2015-2016 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/
'use strict'
var isObject = require('is-extendable')
/**
* > Check that `val` is error.
*
* **Example**
*
* ```js
* const isTypeofError = require('is-typeof-error')
* const PluginError = require('plugin-error')
* const KindError = require('kind-error')
*
* const CustomClass = function () {}
* CustomClass.prototype.foo = function () {}
*
* isTypeofError(new TypeError('test')) // => true
* isTypeofError(new KindError('test')) // => true
* isTypeofError(new SyntaxError('test')) // => true
* isTypeofError(new PluginError('test', 'msg')) // => true
*
* isTypeofError(new CustomClass('test')) // => false
* isTypeofError(new Object({a: 'b'})) // => false
* isTypeofError(new RegExp('test')) // => false
* isTypeofError(Object.create({a: 'b'})) // => false
* isTypeofError(/regex/) // => false
* isTypeofError({a: 'b'}) // => false
* ```
*
* @param {Error} `val`
* @return {Boolean}
* @api public
*/
module.exports = function isTypeofError (val) {
return isObject(val) &&
val instanceof Error &&
typeof val.message === 'string'
}