{"id":27408482,"url":"https://github.com/romaindurand/maju","last_synced_at":"2026-04-26T22:31:33.971Z","repository":{"id":91464547,"uuid":"132677929","full_name":"romaindurand/maju","owner":"romaindurand","description":"A Majority Judgment library","archived":false,"fork":false,"pushed_at":"2025-12-22T01:04:18.000Z","size":374,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-23T12:46:49.911Z","etag":null,"topics":["javascript-library","judgement","majority","npm","npm-module","poll"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/romaindurand.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-05-08T23:57:09.000Z","updated_at":"2025-12-22T01:04:21.000Z","dependencies_parsed_at":"2023-07-17T03:00:55.159Z","dependency_job_id":null,"html_url":"https://github.com/romaindurand/maju","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/romaindurand/maju","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romaindurand%2Fmaju","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romaindurand%2Fmaju/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romaindurand%2Fmaju/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romaindurand%2Fmaju/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/romaindurand","download_url":"https://codeload.github.com/romaindurand/maju/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/romaindurand%2Fmaju/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32315711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T21:09:39.134Z","status":"ssl_error","status_checked_at":"2026-04-26T21:09:21.240Z","response_time":129,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["javascript-library","judgement","majority","npm","npm-module","poll"],"created_at":"2025-04-14T07:19:58.358Z","updated_at":"2026-04-26T22:31:33.966Z","avatar_url":"https://github.com/romaindurand.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# maju 🗳️\n**`maju`** (for **ma**jority **ju**dgment) is a Javascript library implementing the majority judgment voting system.\n\n[More info on majority judgment](#majority-judgment)\n\n## Usage\nAdd maju to your project with `npm i maju` or `yarn add maju`\n\nThe exposed method allows you to create a poll:\n\n```javascript\nimport createPoll from 'maju';\n\nconst myPoll = createPoll(['Matrix', 'Ghostbusters', 'Terminator', 'Stargate'])\n```\n\nUse the poll's `addVotes()` function to cast votes. The array parameter must contain an object for each vote. Each vote object must include a property for every poll option. The value must be an integer between 0 and 5 (configurable via `createPoll` options), the higher the better.\n\n```javascript\nmyPoll.addVotes([{ Matrix: 5, Stargate: 1, Ghostbusters: 0, Terminator: 2 }])\n```\n\nUse the poll's `getResults()` function to get detailed results.\n\n```javascript\nconsole.log(myPoll.getResults())\n```\n\n### Customize grading levels\n\n```javascript\nconst myPoll = createPoll(['Matrix', 'Ghostbusters', 'Terminator', 'Stargate'], { GRADING_LEVELS: 6 })\n```\n\n### Error Handling\n\nYou can distinguish between different error types to handle them effectively:\n\n```typescript\nimport { InvalidVoteError, VoteStructureError } from 'maju';\n\ntry {\n  poll.addVotes([userVote]);\n} catch (error) {\n  if (error instanceof VoteStructureError) {\n    console.error(`Invalid vote keys. Expected: ${error.expected}, Given: ${error.given}`);\n  } else if (error instanceof InvalidVoteError) {\n    console.error(\"Vote rejected:\", error.message);\n  }\n}\n```\n\n## API\n\n### `getResults()`\nReturns an array of `OptionResult` objects, sorted by rank (winner first). Each result contains:\n- `rank`: The rank of the option (0 is best). Ties have the same rank.\n- `name`: The option name.\n\n- `medianGrade`: The median grade value.\n- `distribution`: Array of length `GRADING_LEVELS` with objects `{ count, percentage }` for each grade.\n\n## Demo\n\n```\npnpm i\npnpm demo\n```\n\nRefer to `demo/index.js` for a usage example\n- `pnpm demo:node` for a node-only example\n- `pnpm demo` for a browser usage example\n\n## Majority Judgment\nMajority judgment is a single-winner voting system. Voters freely grade each candidate in one of several named ranks, for instance from \"excellent\" to \"bad\", and the candidate with the highest median grade is the winner.\n\n### Resources\n- Wikipedia article: https://en.wikipedia.org/wiki/Majority_judgment\n- ScienceEtonnante video: https://www.youtube.com/watch?v=ZoGH7d51bvc (French audio, English subtitles)\n- On voting systems: https://www.youtube.com/watch?v=vfTJ4vmIsO4 (French audio, English subtitles)\n- Science4All video: https://www.youtube.com/watch?v=_MAo8pUl0U4 (French audio)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromaindurand%2Fmaju","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fromaindurand%2Fmaju","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fromaindurand%2Fmaju/lists"}