{"id":22430570,"url":"https://github.com/sd0e/parsemath","last_synced_at":"2026-03-19T22:51:29.380Z","repository":{"id":65414737,"uuid":"591706502","full_name":"sd0e/parsemath","owner":"sd0e","description":"🔢 Fast JS math equation parser","archived":false,"fork":false,"pushed_at":"2023-10-24T21:36:09.000Z","size":244,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-20T05:32:24.949Z","etag":null,"topics":["math","parse-equation"],"latest_commit_sha":null,"homepage":"https://git.sebdoe.com/parsemath/","language":"HTML","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/sd0e.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-01-21T15:58:23.000Z","updated_at":"2023-10-29T21:07:22.000Z","dependencies_parsed_at":"2023-02-12T15:31:27.245Z","dependency_job_id":"bfc0d33e-5f27-4a9c-a0c5-87a242d85bdf","html_url":"https://github.com/sd0e/parsemath","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sd0e%2Fparsemath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sd0e%2Fparsemath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sd0e%2Fparsemath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sd0e%2Fparsemath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sd0e","download_url":"https://codeload.github.com/sd0e/parsemath/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245798354,"owners_count":20673902,"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":["math","parse-equation"],"created_at":"2024-12-05T21:08:54.021Z","updated_at":"2026-01-06T19:03:00.988Z","avatar_url":"https://github.com/sd0e.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# parsemath\n\n[![View coverage report image](https://img.shields.io/badge/view%20coverage%20report-click-informational)](https://git.sebdoe.com/parsemath/coverage/lcov-report/)\n\n\u003e Disclaimer: I am not an expert in number parsing and, although many unit tests are in place for this library, I cannot confirm that it will work for all use cases, so do not use this library if reliability is important. **I do not hold any liability if this code does not work as expected.**\n\n\u003e Not related to npm package of same name\n\nA JavaScript library which parses an equation in string format to a number. It skips the traditional method of generating a syntax tree, instead evaluating the expression from the inside directly through a recursive method, resulting in code which often executes much more quickly than others (and sometimes orders of magnitude faster). This speed does not come at the cost of more advanced features; it supports implicit multiplication, multiple units of angles, and multiple custom variables.\n\n## Current abilities\n* Evaluate mathematical expressions with the following operators: `^`, `*`, `/`, `+`, `-`\n* Evaluate mathematical expressions with the following operators containing a number inside the brackets, with **trigonometric values represented in radians by default**: `sqrt()`, `sin()`, `cos()`, `tan()`, `asin()`, `acos()`, `atan()`, `abs()`\n* Evaluate mathematical expressions with brackets\n* Evaluate mathematical expressions containing multi-digit positive and negative integers and floats\n* Evaluate mathematical expressions involving the mathematical constants `e` and `π` (the `enableConstants` parameter must be set to true for this to work)\n* Evaluate mathematical expressions involving variables in the Roman and Greek alphabets\n* Evaluate mathematical expressions with trigonometric functions using *either* radians or degrees\n\n## Certain things that are known to not work\n(This is not an exhaustive list)\n* Placing a number or variable immediately before a function (e.g. `8cos(0.5)`)\n* Modulus brackets (`|`) (please instead use `abs()`)\n\n## Usage\nThe function accepts the following arguments in their respective order:\n* **equation** (*string*): the equation to be parsed\n* **enableConstants** (*boolean*, default is `true`): whether to enable the mathematical constants `e` and `π` when parsing equation\n* **variables** (*object*, default is `null`): any custom variables to be used when parsing equation\n* **angleMode** (*string*, can be either `rad` or `deg`, default is `rad`): the mode to be used with the angles\n\n#### Example `variables` object\n```js\n{\n    \"x\": 0,\n    \"y\": -4.3\n}\n```\n\n## Examples\n#### Simple Equation\n```js\nParseMath('5 + 3 * 6 / 2') // 14\n```\n\n#### Equation with Constants\n```js\nNumber(ParseMath('3e').toFixed(3)) // 8.155\n```\n\n#### Equation with Custom Variables\n```js\nParseMath('3x^2 - 5x + 3', true, {\"x\": 6}) // 81\n```\n\n#### Equation with Trigonometric Function\n\n```js\nNumber(ParseMath('5*1-(sin(2)*tan(2))').toFixed(3)) // 6.987\n```\n\n#### Equation with Trigonometric Function in Degrees\n\n```js\nNumber(ParseMath('sin(arccos(0.5) + 1)', false, null, 'deg').toFixed(3)) // 0.875\n```\n\nNote that this library has the standard JavaScript floating point math issue where there are occasionally inaccurate results, such as `0.1 + 0.2 = 0.30000000000000004`. This can be resolved by the user by rounding the answer to an appropriate number of decimal places.\n\nAgain, this library has not been fully tested so may not work as expected with these abilities.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsd0e%2Fparsemath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsd0e%2Fparsemath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsd0e%2Fparsemath/lists"}