-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ESM usage documentation
- Loading branch information
Showing
1 changed file
with
31 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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'); | ||
|
@@ -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 | ||
|