{"id":17312598,"url":"https://github.com/ndaidong/average-rating","last_synced_at":"2025-04-23T08:52:02.699Z","repository":{"id":2047687,"uuid":"45616572","full_name":"ndaidong/average-rating","owner":"ndaidong","description":"Calculate  average score and rating based on Wilson Score Equation","archived":false,"fork":false,"pushed_at":"2024-06-23T10:29:30.000Z","size":118,"stargazers_count":33,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T15:41:49.535Z","etag":null,"topics":["rating","rating-stars","rating-system","scoring","wilson-score-equation"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ndaidong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2015-11-05T14:32:33.000Z","updated_at":"2024-10-30T11:17:20.000Z","dependencies_parsed_at":"2023-07-10T21:01:50.121Z","dependency_job_id":null,"html_url":"https://github.com/ndaidong/average-rating","commit_stats":{"total_commits":65,"total_committers":2,"mean_commits":32.5,"dds":"0.10769230769230764","last_synced_commit":"b34329d988b9a5d1249b5355af1efb36b86fb63d"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndaidong%2Faverage-rating","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndaidong%2Faverage-rating/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndaidong%2Faverage-rating/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndaidong%2Faverage-rating/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ndaidong","download_url":"https://codeload.github.com/ndaidong/average-rating/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250403254,"owners_count":21424774,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rating","rating-stars","rating-system","scoring","wilson-score-equation"],"created_at":"2024-10-15T12:44:01.493Z","updated_at":"2025-04-23T08:52:02.679Z","avatar_url":"https://github.com/ndaidong.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# average-rating\n\nCalculate average and scoring based on Wilson Score Equation\n\n![CodeQL](https://github.com/ndaidong/average-rating/workflows/CodeQL/badge.svg)\n[![CI test](https://github.com/ndaidong/average-rating/workflows/ci-test/badge.svg)](https://github.com/ndaidong/average-rating/actions)\n[![Coverage Status](https://coveralls.io/repos/github/ndaidong/average-rating/badge.svg)](https://coveralls.io/github/ndaidong/average-rating)\n[![NPM](https://img.shields.io/npm/v/%40ndaidong%2Faverage-rating?color=32bb24)](https://www.npmjs.com/package/@ndaidong/average-rating)\n[![JSR](https://jsr.io/badges/@ndaidong/average-rating?color=32bb24)](https://jsr.io/@ndaidong/average-rating)\n\n![Google app on Google Play](https://i.imgur.com/XKEEpdb.png)\n\n## Setup \u0026 Usage\n\n### Deno\n\nhttps://jsr.io/@ndaidong/average-rating\n\n```sh\ndeno add @ndaidong/average-rating\n\n# npm (use any of npx, yarn dlx, pnpm dlx, or bunx)\nnpx jsr add @ndaidong/average-rating\n```\n\n```ts\n// es6 module\nimport { average, rate, score } from \"@ndaidong/average-rating\";\n\n// CommonJS\nconst {\n  score,\n  rate,\n  average,\n} = require(\"@ndaidong/average-rating\");\n\nscore(80, 20); // =\u003e 0.71\nrate([134055, 57472, 143135, 365957, 1448459]); // =\u003e 0.84\naverage([134055, 57472, 143135, 365957, 1448459]); // =\u003e 4.4\n```\n\nYou can use JSR packages without an install step using `jsr:` specifiers:\n\n```ts\nimport { average } from \"jsr:@ndaidong/average-rating\";\n\naverage([134055, 57472, 143135, 365957, 1448459]); // =\u003e 4.4\n```\n\nYou can also use `npm:` specifiers as before:\n\n```ts\nimport { average } from \"npm:@ndaidong/average-rating\";\n\naverage([134055, 57472, 143135, 365957, 1448459]); // =\u003e 4.4\n```\n\nOr import from esm.sh\n\n```ts\nimport { average } from \"https://esm.sh/@ndaidong/average-rating\";\n\naverage([134055, 57472, 143135, 365957, 1448459]); // =\u003e 4.4\n```\n\n### Node.js \u0026 Bun\n\nhttps://www.npmjs.com/package/@ndaidong/average-rating\n\n```bash\nnpm i @ndaidong/average-rating\n# pnpm\npnpm i @ndaidong/average-rating\n# yarn\nyarn add @ndaidong/average-rating\n# bun\nbun add @ndaidong/average-rating\n```\n\n```ts\nimport { average } from \"@ndaidong/average-rating\";\n\naverage([134055, 57472, 143135, 365957, 1448459]); // =\u003e 4.4\n```\n\nYou can also use CJS style:\n\n```ts\nconst { average } = require(\"@ndaidong/average-rating\");\n\naverage([134055, 57472, 143135, 365957, 1448459]); // =\u003e 4.4\n```\n\n### Browsers:\n\n```html\n\u003cscript type=\"module\"\u003e\nimport { average } from \"https://esm.sh/@ndaidong/average-rating\";\n// import { average } from 'https://unpkg.com/@ndaidong/average-rating/esm/mod.js';\n\naverage([134055, 57472, 143135, 365957, 1448459]) // =\u003e 4.4\n\u003c/script\u003e\n```\n\n## APIs\n\n### .score(Number positive, Number negative)\n\nThis method returns a normalized value between 0 and 1, but it's applicable for systems\nwith only positive and negative ratings (like/dislike, thumbs up/thumbs down).\nExamples include videos on YouTube or answers on Stack Overflow.\nIn these systems, users can express their opinion by voting for either a positive or negative option.\n\nLet's illustrate how this method works with a blog post that received 80 likes and 20 dislikes:\n\n```ts\nimport { score } from \"@ndaidong/average-rating\";\n\nscore(80, 20); // =\u003e 0.71\n```\n\n### .rate(Array ratings)\n\nThis method returns a normalized value between 0 and 1, commonly used in rating systems with 5 levels.\nExamples include applications on Google Play Store or books on Amazon.\nIn these systems, each item receives a user rating between 1 and 5 stars.\n\nLet's take a product with a large volume of reviews as an example. Here's how we calculate its rating:\n\n- 134,055 customers rated it 1 star\n- 57,472 gave it a 2-star rating\n- There are 143,135 ratings of 3 stars\n- It received a 4-star rating from 365,957 users\n- And a whopping 1,448,459 customers rated it 5 stars\n\n```ts\nimport { rate } from \"@ndaidong/average-rating\";\n\nrate([134055, 57472, 143135, 365957, 1448459]); // =\u003e 0.84\n```\n\n##### Update\n\n- Since v1.1.5, this `rate` method accepts custom range of ratings. 5 or more\n  values are OK.\n\n```ts\nconst input = [3, 4, 2, 6, 12, 46, 134, 213, 116, 91, 45, 15, 58, 96, 1654]; // 15 values\nrate(input); // =\u003e 0.85\n\nrate([3, 4, 2, 6, 12, 46, 134, 213, 116, 91]); // =\u003e 0.74\n```\n\n### .average(Array ratings)\n\nReturn a value from 0 to 5.\n\nCalculate normal average value for the systems of 5 rating levels.\n\n```ts\nimport { average } from \"@ndaidong/average-rating\";\n\naverage([134055, 57472, 143135, 365957, 1448459]); // =\u003e 4.4\n```\n\n## Development\n\nSince v3.x.x, we switched to [Deno](https://docs.deno.com/runtime/manual/)\nplatform, and use [DNT](https://github.com/denoland/dnt) to build Node.js\npackages.\n\n```bash\ngit clone https://github.com/ndaidong/average-rating.git\ncd average-rating\n\n# test\ndeno test\n\n# build npm packages\ndeno task build\n\ncd npm\nnode test_runner.js\n```\n\n# License\n\nThe MIT License (MIT)\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndaidong%2Faverage-rating","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fndaidong%2Faverage-rating","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndaidong%2Faverage-rating/lists"}