Skip to content

Commit 9eb4a90

Browse files
authored
chore: add another example in docs for fetch api (#8)
1 parent 96d84d2 commit 9eb4a90

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,25 @@ const result3 = await neval(
4242
`,
4343
{
4444
context: {
45-
sleep: async (ms) => {
45+
sleep: async (ms: number) => {
4646
return new Promise((resolve) => setTimeout(resolve, ms));
4747
},
4848
},
4949
}
5050
);
5151
console.log(result3); // Result after 1 second is 2
52+
53+
const result4 = await neval(
54+
`
55+
fetch('https://example.com', { method: 'HEAD' })
56+
.then((resp) => resp.statusText);
57+
`,
58+
{
59+
// By default, the "fetch" API is not available, you must add it to the context
60+
context: { fetch },
61+
}
62+
);
63+
console.log(result4); // OK
5264
```
5365

5466
Importing `neval/register` will register the `neval` function on the global object and overrides the `eval` function.

0 commit comments

Comments
 (0)