@@ -34,51 +34,58 @@ You can find a list of real implementations - [here](/docs/who-use-it.md)
34
34
35
35
### NPM
36
36
37
+
37
38
``` bash
38
39
npm install itemsjs
39
40
```
40
41
42
+ #### Using CommonJS syntax
41
43
``` js
42
44
const itemsjs = require (' itemsjs' )(data, configuration);
43
45
const items = itemsjs .search ();
44
46
```
45
47
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 ();
52
53
```
53
54
55
+ ### Client side
56
+
57
+ ##### To use as an UMD in the browser:
54
58
``` html
55
59
<!-- CDN -->
56
60
<!-- 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 >
58
62
<!-- 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 >
60
64
<!-- 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
+ ```
62
67
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 >
65
73
```
66
74
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 >
70
84
```
71
85
72
- Gulp task:
73
86
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
- ```
80
87
81
- ## Example
88
+ ## Example usage
82
89
83
90
``` bash
84
91
npm install itemsjs
@@ -87,7 +94,7 @@ npm install itemsjs
87
94
wget https://raw.githubusercontent.com/itemsapi/itemsapi-example-data/master/items/imdb.json -O data.json
88
95
```
89
96
90
- Create ` search.js ` :
97
+ Next, create a search.js file with the following content :
91
98
92
99
``` js
93
100
const data = require (' ./data.json' );
@@ -141,7 +148,7 @@ const top_tags = itemsjs.aggregation({
141
148
console .log (JSON .stringify (top_tags, null , 2 ));
142
149
```
143
150
144
- Test that with :
151
+ Run your script with Node.js :
145
152
146
153
``` bash
147
154
node search.js
0 commit comments