Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace var with let and const #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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'
```