From 95ad43fc5d99645c6314265b13216a6eb29cf354 Mon Sep 17 00:00:00 2001 From: Mateusz Date: Thu, 9 Nov 2023 19:14:31 +0100 Subject: [PATCH] Update README.md ESM usage documentation --- README.md | 55 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 8b1ed6e..00290ea 100644 --- a/README.md +++ b/README.md @@ -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 - + - + - + +``` - - +```html + ``` -```js -itemsjs = itemsjs(data, configuration); -itemsjs.search() +##### To use as an ES module in the browser: +```html + + ``` -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