Skip to content

Commit e0a161f

Browse files
authored
docs: README: require -> import
1 parent 566655b commit e0a161f

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Wrap function to avoid `try-catch` block, resolves `[error, result]`;
2626
Simplest example with `async-await`:
2727

2828
```js
29-
const tryToCatch = require('try-to-catch');
29+
import tryToCatch from 'try-to-catch';
3030
const reject = Promise.reject.bind(Promise);
3131
await tryToCatch(reject, 'hi');
3232
// returns
@@ -36,7 +36,7 @@ await tryToCatch(reject, 'hi');
3636
Can be used with functions:
3737

3838
```js
39-
const tryToCatch = require('try-to-catch');
39+
import tryToCatch from 'try-to-catch';
4040
await tryToCatch(() => 5);
4141
// returns
4242
[null, 5];
@@ -45,12 +45,17 @@ await tryToCatch(() => 5);
4545
Advanced example:
4646

4747
```js
48-
const {readFile, readdir} = require('fs/promises');
49-
const tryToCatch = require('try-to-catch');
48+
import {readFile, readdir} = from 'node:fs/promises';
49+
import tryToCatch from 'try-to-catch';
5050

51-
read(process.argv[2])
52-
.then(console.log)
53-
.catch(console.error);
51+
const [error, data] = await tryToCatch(read, process.argv[2]);
52+
53+
if (error) {
54+
console.error(error);
55+
process.exit(1);
56+
}
57+
58+
console.log(data);
5459

5560
async function read(path) {
5661
const [error, data] = await tryToCatch(readFile, path, 'utf8');

0 commit comments

Comments
 (0)