Skip to content

Commit

Permalink
Docs: Update README with ESM instructions (fixes #474) (#477)
Browse files Browse the repository at this point in the history
* Docs: Update README with ESM instructions (fixes #474)

* Update README.md

* Update docs/README.md
  • Loading branch information
nzakas authored Apr 20, 2021
1 parent 8209e4e commit 671c3aa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ Install:
npm i espree
```

And in your Node.js code:
To use in an ESM file:

```javascript
```js
import * as espree from "espree";

const ast = espree.parse(code);
```

To use in a Common JS file:

```js
const espree = require("espree");

const ast = espree.parse(code);
Expand All @@ -32,10 +40,10 @@ const ast = espree.parse(code);
- `code` [string]() - the code which needs to be parsed.
- `options (Optional)` [Object]() - read more about this [here](#options).

```javascript
const espree = require("espree");
```js
import * as espree from "espree";

const ast = espree.parse(code, options);
const ast = espree.parse(code);
```

**Example :**
Expand Down Expand Up @@ -81,6 +89,8 @@ Even if `options` is empty or undefined or `options.tokens` is `false`, it assig
**Example :**

```js
import * as espree from "espree";

const tokens = espree.tokenize('let foo = "bar"', { ecmaVersion: 6 });
console.log(tokens);
```
Expand Down
20 changes: 15 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ Install:
npm i espree
```

And in your Node.js code:
To use in an ESM file:

```javascript
```js
import * as espree from "espree";

const ast = espree.parse(code);
```

To use in a Common JS file:

```js
const espree = require("espree");

const ast = espree.parse(code);
Expand All @@ -32,10 +40,10 @@ const ast = espree.parse(code);
- `code` [string]() - the code which needs to be parsed.
- `options (Optional)` [Object]() - read more about this [here](#options).

```javascript
const espree = require("espree");
```js
import * as espree from "espree";

const ast = espree.parse(code, options);
const ast = espree.parse(code);
```

**Example :**
Expand Down Expand Up @@ -81,6 +89,8 @@ Even if `options` is empty or undefined or `options.tokens` is `false`, it assig
**Example :**

```js
import * as espree from "espree";

const tokens = espree.tokenize('let foo = "bar"', { ecmaVersion: 6 });
console.log(tokens);
```
Expand Down

0 comments on commit 671c3aa

Please sign in to comment.