Skip to content

Commit 95ad43f

Browse files
authoredNov 9, 2023
Update README.md
ESM usage documentation
1 parent 8217c8b commit 95ad43f

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed
 

‎README.md

+31-24
Original file line numberDiff line numberDiff line change
@@ -34,51 +34,58 @@ You can find a list of real implementations - [here](/docs/who-use-it.md)
3434

3535
### NPM
3636

37+
3738
```bash
3839
npm install itemsjs
3940
```
4041

42+
#### Using CommonJS syntax
4143
```js
4244
const itemsjs = require('itemsjs')(data, configuration);
4345
const items = itemsjs.search();
4446
```
4547

46-
### Client side
47-
48-
or using from the client side:
49-
50-
```bash
51-
npm install itemsjs
48+
#### Using ES Module syntax
49+
```js
50+
import itemsjs from 'itemsjs';
51+
const searchEngine = itemsjs(data, configuration);
52+
const items = searchEngine.search();
5253
```
5354

55+
### Client side
56+
57+
##### To use as an UMD in the browser:
5458
```html
5559
<!-- CDN -->
5660
<!-- unpkg: use the latest release -->
57-
<script src="https://unpkg.com/itemsjs@latest/dist/itemsjs.min.js"></script>
61+
<script src="https://unpkg.com/itemsjs@latest/dist/index.umd.js"></script>
5862
<!-- unpkg: use a specific version -->
59-
<script src="https://unpkg.com/itemsjs@1.0.49/dist/itemsjs.min.js"></script>
63+
<script src="https://unpkg.com/itemsjs@2.1.24/dist/index.umd.js"></script>
6064
<!-- jsdelivr: use a specific version -->
61-
<script src="https://cdn.jsdelivr.net/npm/itemsjs@1.0.49/dist/itemsjs.min.js"></script>
65+
<script src="https://cdn.jsdelivr.net/npm/itemsjs@2.1.24/dist/index.umd.js"></script>
66+
```
6267

63-
<!-- locally -->
64-
<script src="/node_modules/itemsjs/dist/itemsjs.js"></script>
68+
```html
69+
<script>
70+
itemsjs = itemsjs(data, configuration);
71+
itemsjs.search()
72+
</script>
6573
```
6674

67-
```js
68-
itemsjs = itemsjs(data, configuration);
69-
itemsjs.search()
75+
##### To use as an ES module in the browser:
76+
```html
77+
<!-- Include as ES Module -->
78+
<script type="module">
79+
import itemsjs from 'https://unpkg.com/itemsjs@2.1.24/dist/index.module.js';
80+
// Initialize and use itemsjs here
81+
const searchEngine = itemsjs(data, configuration);
82+
searchEngine.search();
83+
</script>
7084
```
7185

72-
Gulp task:
7386

74-
```javascript
75-
function itemjs() {
76-
return src('node_modules/itemsjs/dist/itemsjs.min.js')
77-
.pipe(dest('source/javascripts/'));
78-
}; // Will copy to source/javascripts/itemsjs.min.js
79-
```
8087

81-
## Example
88+
## Example usage
8289

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

90-
Create `search.js`:
97+
Next, create a search.js file with the following content:
9198

9299
```js
93100
const data = require('./data.json');
@@ -141,7 +148,7 @@ const top_tags = itemsjs.aggregation({
141148
console.log(JSON.stringify(top_tags, null, 2));
142149
```
143150

144-
Test that with :
151+
Run your script with Node.js:
145152

146153
```bash
147154
node search.js

0 commit comments

Comments
 (0)
Please sign in to comment.