Skip to content

Commit

Permalink
Add import attributes examples to readme (#22512)
Browse files Browse the repository at this point in the history
  • Loading branch information
queengooborg committed Mar 12, 2024
1 parent fa10f41 commit 8cfa6c0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ yarn add @mdn/browser-compat-data
Then, you can import BCD into your project with either `import` or `require()`:

```js
// ESM with Import Attributes (NodeJS 20+)
import bcd from '@mdn/browser-compat-data' with { type: 'json' };
// ...or...
const { default: bcd } = await import('@mdn/browser-compat-data', {
with: { type: 'json' },
});

// ...or...

// ESM with Import Assertions (NodeJS 16+)
import bcd from '@mdn/browser-compat-data' assert { type: 'json' };
// ...or...
Expand All @@ -48,6 +57,19 @@ const bcd = require('@mdn/browser-compat-data');
You can import `@mdn/browser-compat-data` using a CDN.

```js
// ESM with Import Attributes (Deno 1.37+)
import bcd from 'https://unpkg.com/@mdn/browser-compat-data' with { type: 'json' };
// ...or...
const { default: bcd } = await import(
'https://unpkg.com/@mdn/browser-compat-data',
{
with: { type: 'json' },
}
);

// ...or...

// ESM with Import Assertions (Deno 1.17+)
import bcd from 'https://unpkg.com/@mdn/browser-compat-data' assert { type: 'json' };
// ...or...
const { default: bcd } = await import(
Expand All @@ -56,6 +78,13 @@ const { default: bcd } = await import(
assert: { type: 'json' },
}
);

// ...or...

// Fetch Method (Deno 1.0+)
const bcd = await fetch('https://unpkg.com/@mdn/browser-compat-data').then(
(response) => response.json(),
);
```

### Other Languages
Expand Down

0 comments on commit 8cfa6c0

Please sign in to comment.