Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
- Add eval.js for quick test
  • Loading branch information
ndaidong committed Jan 4, 2022
1 parent 62eeffa commit 9b7f9dc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,28 @@ Calculate average and scoring based on Wilson Score Equation

### Node.js:

Sync v14, ECMAScript modules [have became the official standard format](https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_modules_ecmascript_modules).

Just [enable](https://nodejs.org/api/packages.html#determining-module-system) and enjoy with ES6 import/export syntax.


```js
import {
score,
rate,
average
} from 'average-rating'
```
For regular CommonJS environment, `require` can be used as below:
// with CommonJS environment
// const { score, rate, average } = require('feed-reader/dist/cjs/average-rating.js')
```js
const {
score,
rate,
average
} = require('average-rating/cjs/average-rating.js')
score(80, 20) // => 0.71
average([134055, 57472, 143135, 365957, 1448459]) // => 4.4
rate([134055, 57472, 143135, 365957, 1448459]) // => 0.84
```
##### Note:
> Since Node.js v14, ECMAScript modules [have became the official standard format](https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_modules_ecmascript_modules).
> Just ensure that you are [using module system](https://nodejs.org/api/packages.html#determining-module-system) and enjoy with ES6 import/export syntax.
### Browsers:
Currently ECMAScript modules work fine on almost browsers:
Expand Down
14 changes: 14 additions & 0 deletions eval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// eval.js

import {
score,
rate,
average
} from './src/main.js'

const scoring = [80, 20]
const rating = [134055, 57472, 143135, 365957, 1448459]

console.log(`score(${scoring.join(', ')}) // => ${score(...scoring)}`)
console.log(`average([${rating.join(', ')}]) // => ${average(rating)}`)
console.log(`rate([${rating.join(', ')}]) // => ${rate(rating)}`)
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"pretest": "npm run lint",
"test": "NODE_ENV=test jest --verbose --coverage=true --unhandled-rejections=strict --detectOpenHandles",
"build": "node build src/main.js",
"eval": "node eval",
"reset": "node reset"
},
"devDependencies": {
Expand Down

0 comments on commit 9b7f9dc

Please sign in to comment.