{"id":18292147,"url":"https://github.com/emmetio/math-expression","last_synced_at":"2025-04-05T10:31:10.629Z","repository":{"id":19676735,"uuid":"87630628","full_name":"emmetio/math-expression","owner":"emmetio","description":"Parse \u0026 evaluate simple math expressions","archived":false,"fork":false,"pushed_at":"2023-05-10T08:06:57.000Z","size":118,"stargazers_count":10,"open_issues_count":7,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-29T22:37:58.756Z","etag":null,"topics":["evaluate","expression","math"],"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/emmetio.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":"2017-04-08T11:58:24.000Z","updated_at":"2024-10-04T10:57:26.000Z","dependencies_parsed_at":"2023-01-13T20:31:11.333Z","dependency_job_id":"bbf9eade-c925-46d2-9936-0114fb186a63","html_url":"https://github.com/emmetio/math-expression","commit_stats":{"total_commits":29,"total_committers":1,"mean_commits":29.0,"dds":0.0,"last_synced_commit":"c6e424e3cbdb6631e230bb172774b022635796a4"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmetio%2Fmath-expression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmetio%2Fmath-expression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmetio%2Fmath-expression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmetio%2Fmath-expression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emmetio","download_url":"https://codeload.github.com/emmetio/math-expression/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247324620,"owners_count":20920682,"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":["evaluate","expression","math"],"created_at":"2024-11-05T14:16:52.567Z","updated_at":"2025-04-05T10:31:10.263Z","avatar_url":"https://github.com/emmetio.png","language":"TypeScript","readme":"# Math expression parser and evaluator\n\nFast and small (less than 2KB minified and gzipped) zero-dependency math expression parser and evaluator.\n\n```js\nimport evaluate from '@emmetio/math-expression';\n\nconsole.log(evaluate('2 * (-3 + 5)')); // 4\n```\n\n## Motivation\n\nIn JavaScript, you can use built-in `eval()` function to evaluate expressions:\n\n```js\nconsole.log(eval('2 * (-3 + 5)')); // 4\n```\n\nBut in most modern JavaScript environments `eval()` function is considered harmful since it can evaluate _any_ arbitrary JS code. And in some cases (like in [Atom](https://atom.io) editor) it’s disabled by default due to security reasons.\n\nWith `@emmetio/math-expression` module you can safely parse \u0026 evaluate basic math expressions in any JS environment.\n\n## Extract expression from text\n\nThis module is used by [Emmet](https://emmet.io) project to evaluate math expression in-place in code source. A default user workflow is to enter math expression somewhere in source code and run action to evaluate it. You can use `extract` function to extract math expression from given source code, starting at specified position:\n\n```js\nimport evaluate, { extract } from '@emmetio/math-expression';\n\nconst code = 'Here goes math: 2 + 3 foo bar';\nconst [start, end] = extract(code, 21); // 16, 21\nconst expr = code.substring(start, end); // 2 + 3\nconsole.log(evaluate(expr)); // 5\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmetio%2Fmath-expression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femmetio%2Fmath-expression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmetio%2Fmath-expression/lists"}