{"id":16930595,"url":"https://github.com/tmccombs/rollexpr","last_synced_at":"2025-06-14T13:38:15.974Z","repository":{"id":57355575,"uuid":"427599168","full_name":"tmccombs/rollexpr","owner":"tmccombs","description":"Simple library for evaluating expressions including variables and dice rolls, as are frequently used in role playing games.","archived":false,"fork":false,"pushed_at":"2023-09-28T03:35:41.000Z","size":80,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-03T18:01:46.482Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tmccombs.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-13T07:35:00.000Z","updated_at":"2021-11-24T18:48:21.000Z","dependencies_parsed_at":"2024-09-18T11:42:15.344Z","dependency_job_id":"20bca1b4-f4b1-4973-8a99-b69eff8344ed","html_url":"https://github.com/tmccombs/rollexpr","commit_stats":{"total_commits":14,"total_committers":1,"mean_commits":14.0,"dds":0.0,"last_synced_commit":"5ad1f96668234a7c3b68152b776a3e45acb08c71"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tmccombs/rollexpr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccombs%2Frollexpr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccombs%2Frollexpr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccombs%2Frollexpr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccombs%2Frollexpr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tmccombs","download_url":"https://codeload.github.com/tmccombs/rollexpr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmccombs%2Frollexpr/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259774597,"owners_count":22909163,"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":[],"created_at":"2024-10-13T20:42:02.703Z","updated_at":"2025-06-14T13:38:15.913Z","avatar_url":"https://github.com/tmccombs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"RollExpr is a javascript/typescript library for parsing and evaluating expressions that can\ninclude variables, and dice rolls, as are commonly used in roll playing games.\n\n# Example expressions\n\n- `1d20 + DEX + PROF`\n- `3d8 + STR`\n- `2d6 - 1d4 + 2`\n- `3d8 / 2`\n\n\n# Usage\n\n```javascript\nimport {parse} from 'rollexpr';\n\nconst expr = parse('1d20 + DEX + 3');\n\nconst context = {DEX: 2};\nconsole.log(expr.calc(context)); // Print random int in [1, 20] + 5\nconsole.log(expr.toString()); // Print \"1d20 + DEX + 3\"\nconsole.log(expr.simplify(context).toString()); // Print \"1d20 + 5\"\n```\n\n# Syntax\n\n## Operators\n\n`RollExpr` supports the following mathemtical operators, with the normal precedence:\n\n- `+` and `-`\n- `*` and `/`\n- `(` and `)`\n\n## Literals\n\n`RollExpr` supports literal numbers, which may be integers or floating point. Floating\npoint numbers must be one or more digits followed by decimal, then one or more digits. Integers must\nbe just a sequence of digits. Numbers are always assumed to be decimal. Either can optionally be preceded by a `-` to make it negative.\n\nThe supported formats may be extended in the future.\n\n## Variables\n\nAn expression can contain variables, which are a (ASCII) letter, underscore (`_`), or dollar sign (`$`)\nfollowed by zero or more letters, underscores, dollar signs, digits, and periods (`.`).\n\nThese variables can be substituted with values at evaluation time, or 0 if not supplied.\n\n## Die rolls\n\nA die roll is represented by the number of rolls followed by a \"d\", then the number of sides on each\ndie, with an optional modifier suffix. For example `1d4` rolls a single four-sided die, `4d6` rolls\nfour six-sided dice, and `2d20h` rolls two 2-sided dice, and uses the value of the higher one.\n\nThe currently supported modifiers are `h` which uses the highest die roll, and `l` which uses\nthe lowest die roll. So `2d20h` would be a roll with advantage and `2d20l` would be a roll with\ndisadvantage in D\u0026D.\n\n\n## ABNF of expression syntax\n\nThis uses the ABNF specification as described in [RFC-5234](https://datatracker.ietf.org/doc/html/rfc5234).\n\n\n```abnf\nexpr = term / expr \"+\" term / expr \"-\" term\nterm = factor / term \"*\" factor / term \"/\" factor\nfactor = symbol / roll / literal / \"(\" expr \")\"\nsymbol = (ALPHA / \"_\" / \"$\" ) *(ALPHA / DIGIT / \"_\" / \"$\" / \".\")\nliteral = [ \"-\" ] 1*DIGIT [ \".\" 1*DIGIT ]\nroll = 1*DIGIT \"d\" 1*DIGIT [ roll_modifier ]\nroll_modifier = \"h\" / \"l\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmccombs%2Frollexpr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftmccombs%2Frollexpr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmccombs%2Frollexpr/lists"}