From 6949b997f6692778197580d595faa72af7cd6ff2 Mon Sep 17 00:00:00 2001 From: Vlad Frangu Date: Tue, 7 Nov 2023 18:37:50 +0200 Subject: [PATCH] chore: tweak readme --- README.md | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c7ed263..baa953d 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,28 @@ Got Scraping is a small but powerful [`got` extension](https://github.com/sindre $ npm install got-scraping ``` -**Note:** -> This project is ESM only, which means it can only be imported using the `import` statement or the `import()` method. It is not possible to `require()` it. +# The module is now ESM only + +This means you have to import it by using an `import` expression, or the `import()` method. You can do so by either migrating your project to ESM, or importing `got-scraping` in an async context + +```diff +-const { gotScraping } = require('got-scraping'); ++import { gotScraping } from 'got-scraping'; +``` + +If you cannot migrate to ESM, here's an example of how to import it in an async context: + +```javascript +let gotScraping; + +async function fetchWithGotScraping(url) { + gotScraping ??= (await import('got-scraping')).gotScraping; + + return gotScraping.get(url); +} +``` +**Note:** > - Node.js >=16 is required due to instability of HTTP/2 support in lower versions. ## API @@ -27,17 +46,6 @@ gotScraping .then( ({ body }) => console.log(body)); ``` -```javascript -// If you're still using CJS and cannot use the import syntax -let gotScraping; - -async function fetchWithGotScraping(url) { - gotScraping ??= (await import('got-scraping')).gotScraping; - - return gotScraping.get(url); -} -``` - ### options #### `proxyUrl`