Skip to content

Commit a3bb442

Browse files
authored
docs: update readme to use ESM (#68)
1 parent 7515059 commit a3bb442

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,24 @@ The primary export of `check-error` is an object which has the following methods
4141
* `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.
4242

4343
```js
44-
var checkError = require('check-error');
44+
import * as checkError 'check-error';
4545
```
4646

4747
#### .compatibleInstance(err, errorLike)
4848

4949
```js
50-
var checkError = require('check-error');
50+
import * as checkError 'check-error';
5151

52-
var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
53-
var caughtErr;
52+
const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
53+
let caughtErr;
5454

5555
try {
5656
funcThatThrows();
5757
} catch(e) {
5858
caughtErr = e;
5959
}
6060

61-
var sameInstance = caughtErr;
61+
const sameInstance = caughtErr;
6262

6363
checkError.compatibleInstance(caughtErr, sameInstance); // true
6464
checkError.compatibleInstance(caughtErr, new TypeError('Another error')); // false
@@ -67,10 +67,10 @@ checkError.compatibleInstance(caughtErr, new TypeError('Another error')); // fal
6767
#### .compatibleConstructor(err, errorLike)
6868

6969
```js
70-
var checkError = require('check-error');
70+
import * as checkError 'check-error';
7171

72-
var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
73-
var caughtErr;
72+
const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
73+
let caughtErr;
7474

7575
try {
7676
funcThatThrows();
@@ -86,18 +86,18 @@ checkError.compatibleConstructor(caughtErr, RangeError); // false
8686
#### .compatibleMessage(err, errMatcher)
8787

8888
```js
89-
var checkError = require('check-error');
89+
import * as checkError 'check-error';
9090

91-
var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
92-
var caughtErr;
91+
const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
92+
let caughtErr;
9393

9494
try {
9595
funcThatThrows();
9696
} catch(e) {
9797
caughtErr = e;
9898
}
9999

100-
var sameInstance = caughtErr;
100+
const sameInstance = caughtErr;
101101

102102
checkError.compatibleMessage(caughtErr, /TypeError$/); // true
103103
checkError.compatibleMessage(caughtErr, 'I am a'); // true
@@ -108,37 +108,37 @@ checkError.compatibleMessage(caughtErr, 'I do not exist'); // false
108108
#### .getConstructorName(errorLike)
109109

110110
```js
111-
var checkError = require('check-error');
111+
import * as checkError 'check-error';
112112

113-
var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
114-
var caughtErr;
113+
const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
114+
let caughtErr;
115115

116116
try {
117117
funcThatThrows();
118118
} catch(e) {
119119
caughtErr = e;
120120
}
121121

122-
var sameInstance = caughtErr;
122+
const sameInstance = caughtErr;
123123

124124
checkError.getConstructorName(caughtErr) // 'TypeError'
125125
```
126126

127127
#### .getMessage(err)
128128

129129
```js
130-
var checkError = require('check-error');
130+
import * as checkError 'check-error';
131131

132-
var funcThatThrows = function() { throw new TypeError('I am a TypeError') };
133-
var caughtErr;
132+
const funcThatThrows = function() { throw new TypeError('I am a TypeError') };
133+
let caughtErr;
134134

135135
try {
136136
funcThatThrows();
137137
} catch(e) {
138138
caughtErr = e;
139139
}
140140

141-
var sameInstance = caughtErr;
141+
const sameInstance = caughtErr;
142142

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

0 commit comments

Comments
 (0)