Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
ESM usage documentation
  • Loading branch information
cigolpl authored Nov 9, 2023
1 parent 8217c8b commit 95ad43f
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,51 +34,58 @@ You can find a list of real implementations - [here](/docs/who-use-it.md)

### NPM


```bash
npm install itemsjs
```

#### Using CommonJS syntax
```js
const itemsjs = require('itemsjs')(data, configuration);
const items = itemsjs.search();
```

### Client side

or using from the client side:

```bash
npm install itemsjs
#### Using ES Module syntax
```js
import itemsjs from 'itemsjs';
const searchEngine = itemsjs(data, configuration);
const items = searchEngine.search();
```

### Client side

##### To use as an UMD in the browser:
```html
<!-- CDN -->
<!-- unpkg: use the latest release -->
<script src="https://unpkg.com/itemsjs@latest/dist/itemsjs.min.js"></script>
<script src="https://unpkg.com/itemsjs@latest/dist/index.umd.js"></script>
<!-- unpkg: use a specific version -->
<script src="https://unpkg.com/itemsjs@1.0.49/dist/itemsjs.min.js"></script>
<script src="https://unpkg.com/itemsjs@2.1.24/dist/index.umd.js"></script>
<!-- jsdelivr: use a specific version -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/itemsjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.umd.js"></script>
```

<!-- locally -->
<script src="/node_modules/itemsjs/dist/itemsjs.js"></script>
```html
<script>
itemsjs = itemsjs(data, configuration);
itemsjs.search()
</script>
```

```js
itemsjs = itemsjs(data, configuration);
itemsjs.search()
##### To use as an ES module in the browser:
```html
<!-- Include as ES Module -->
<script type="module">
import itemsjs from 'https://unpkg.com/[email protected]/dist/index.module.js';
// Initialize and use itemsjs here
const searchEngine = itemsjs(data, configuration);
searchEngine.search();
</script>
```

Gulp task:

```javascript
function itemjs() {
return src('node_modules/itemsjs/dist/itemsjs.min.js')
.pipe(dest('source/javascripts/'));
}; // Will copy to source/javascripts/itemsjs.min.js
```

## Example
## Example usage

```bash
npm install itemsjs
Expand All @@ -87,7 +94,7 @@ npm install itemsjs
wget https://raw.githubusercontent.com/itemsapi/itemsapi-example-data/master/items/imdb.json -O data.json
```

Create `search.js`:
Next, create a search.js file with the following content:

```js
const data = require('./data.json');
Expand Down Expand Up @@ -141,7 +148,7 @@ const top_tags = itemsjs.aggregation({
console.log(JSON.stringify(top_tags, null, 2));
```

Test that with :
Run your script with Node.js:

```bash
node search.js
Expand Down

0 comments on commit 95ad43f

Please sign in to comment.