Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,24 @@ The primary export of `check-error` is an object which has the following methods
* `getMessage(err)` - Retrieves the message of an error or `err` itself if it's a String. If `err` or `err.message` is undefined we return an empty String.

```js
var checkError = require('check-error');
const checkError = require('check-error');
```

#### .compatibleInstance(err, errorLike)

```js
var checkError = require('check-error');
const checkError = require('check-error');

var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
var caughtErr;
const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
let caughtErr;

try {
funcThatThrows();
} catch(e) {
caughtErr = e;
}

var sameInstance = caughtErr;
let sameInstance = caughtErr;

checkError.compatibleInstance(caughtErr, sameInstance); // true
checkError.compatibleInstance(caughtErr, new TypeError('Another error')); // false
Expand All @@ -127,10 +127,10 @@ checkError.compatibleInstance(caughtErr, new TypeError('Another error')); // fal
#### .compatibleConstructor(err, errorLike)

```js
var checkError = require('check-error');
const checkError = require('check-error');

var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
var caughtErr;
const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
let caughtErr;

try {
funcThatThrows();
Expand All @@ -146,18 +146,18 @@ checkError.compatibleConstructor(caughtErr, RangeError); // false
#### .compatibleMessage(err, errMatcher)

```js
var checkError = require('check-error');
const checkError = require('check-error');

var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
var caughtErr;
const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
let caughtErr;

try {
funcThatThrows();
} catch(e) {
caughtErr = e;
}

var sameInstance = caughtErr;
let sameInstance = caughtErr;

checkError.compatibleMessage(caughtErr, /TypeError$/); // true
checkError.compatibleMessage(caughtErr, 'I am a'); // true
Expand All @@ -168,37 +168,37 @@ checkError.compatibleMessage(caughtErr, 'I do not exist'); // false
#### .getConstructorName(errorLike)

```js
var checkError = require('check-error');
const checkError = require('check-error');

var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
var caughtErr;
const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
let caughtErr;

try {
funcThatThrows();
} catch(e) {
caughtErr = e;
}

var sameInstance = caughtErr;
let sameInstance = caughtErr;

checkError.getConstructorName(caughtErr) // 'TypeError'
```

#### .getMessage(err)

```js
var checkError = require('check-error');
const checkError = require('check-error');

var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
var caughtErr;
const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
let caughtErr;

try {
funcThatThrows();
} catch(e) {
caughtErr = e;
}

var sameInstance = caughtErr;
let sameInstance = caughtErr;

checkError.getMessage(caughtErr) // 'I am a TypeError'
```