{"id":50334481,"url":"https://github.com/komed3/math-formula-parser","last_synced_at":"2026-05-29T12:31:00.790Z","repository":{"id":348678968,"uuid":"1171442282","full_name":"komed3/math-formula-parser","owner":"komed3","description":"TypeScript parser for complex mathematical formulas into Abstract Syntax Trees (AST)","archived":false,"fork":false,"pushed_at":"2026-05-21T09:14:42.000Z","size":318,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-05-21T17:09:17.354Z","etag":null,"topics":["ast","expression","formula","mathematics","npm-package","parser"],"latest_commit_sha":null,"homepage":"https://npmjs.com/math-formula-parser","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/komed3.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-03T08:31:04.000Z","updated_at":"2026-05-21T09:14:39.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/komed3/math-formula-parser","commit_stats":null,"previous_names":["komed3/math-formula-parser"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/komed3/math-formula-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komed3%2Fmath-formula-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komed3%2Fmath-formula-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komed3%2Fmath-formula-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komed3%2Fmath-formula-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/komed3","download_url":"https://codeload.github.com/komed3/math-formula-parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komed3%2Fmath-formula-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33652977,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-29T02:00:06.066Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["ast","expression","formula","mathematics","npm-package","parser"],"created_at":"2026-05-29T12:30:58.876Z","updated_at":"2026-05-29T12:31:00.783Z","avatar_url":"https://github.com/komed3.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Math Formula Parser\n\nThe **Math Formula Parser** is a flexible library for parsing and analyzing mathematical formulas, implemented in TypeScript.\nIt provides tools to tokenize, parse into an Abstract Syntax Tree (AST), and perform various analyses on formulas, such as extracting variables, constants, and functions, as well as calculating formula depth and node counts.\n\nThe library is designed to be lightweight, easy to use, and extensible, making it suitable for a wide range of applications that involve processing mathematical expressions.\n\n## Installation\n\nInstall from npm:\n\n```bash\nnpm install math-formula-parser\n```\n\n## Usage\n\nThis library is distributed in multiple formats to support various development environments:\n\n### ES Modules (ESM)\n\nThe default choice for modern projects, supporting tree-shaking and modern build tools (Vite, Webpack, etc.).\n\n```ts\nimport { Formula } from 'math-formula-parser';\n\nconst formula = new Formula( 'sin(x) + pi' );\nconsole.log( formula.ast );\n```\n\n### CommonJS (CJS)\n\nSpecifically designed for integration into standard Node.js applications.\n\n```js\nconst { Formula } = require( 'math-formula-parser' );\n\nconst formula = new Formula( 'sin(x) + pi' );\nconsole.log( formula.ast );\n```\n\n### UMD / Browser\n\nFor direct usage in the browser. You can include the script via CDN or from the `dist` folder. The library is exposed under the global variable `FormulaParser`.\n\n```html\n\u003cscript src=\"node_modules/math-formula-parser/dist/bundle.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  const formula = new FormulaParser.Formula( 'sin(x) + pi' );\n  console.log( formula.visualize() );\n\u003c/script\u003e\n```\n\nFor production, it is recommended to use the minified version: `dist/bundle.min.js`.\n\n## API reference\n\n### Formula Class\n\n#### Constructor\n\n- `new Formula( formula?: string )`  \n  Creates a new instance of `Formula`. If a formula string is provided, it is automatically parsed.\n\n#### Analysis \u0026 Parsing\n\n- `parse( formula: string ) : ASTNode`  \n  Parses a mathematical formula string into an AST.\n- `parseAndAnalyze( formula: string ) : AnalysisResult`  \n  Parses a formula and performs a complete analysis, returning an object with AST, variables, constants, functions, depth, node count, and string representation.\n- `getVariables( ast?: ASTNode ) : Set\u003c string \u003e`  \n  Extracts all unique variable names from the formula's AST.\n- `getConstants( ast?: ASTNode ) : Set\u003c string \u003e`  \n  Extracts all unique constant names from the formula's AST.\n- `getFunctions( ast?: ASTNode ) : Set\u003c string \u003e`  \n  Extracts all unique function names from the formula's AST.\n- `getDepth( ast?: ASTNode ) : number`  \n  Calculates the maximum depth of the formula's AST.\n- `getNodeCount( ast?: ASTNode ) : number`  \n  Counts the total number of nodes in the formula's AST.\n\n#### Visualization \u0026 Output\n\n- `toString( ast?: ASTNode ) : string`  \n  Returns a string representation of the formula's AST.\n- `visualize( ast?: ASTNode, options?: VisualizationOptions ) : string`  \n  Returns a visual tree-like string representation of the formula's AST.\n- `visualizeCompact( ast?: ASTNode ) : string`  \n  Returns a compact visual string representation of the formula's AST (same as `toString()`).\n- `visualizeJSON( ast?: ASTNode, indent = 2 ) : string`  \n  Returns a JSON string representation of the formula's AST.\n\n#### Static Methods\n\n- `Formula.instructionSet() : InstructionSet`  \n  Returns an overview of the supported instruction set including version, constants, functions, and operators.\n- `Formula.availableConstants() : Record\u003c string, number \u003e`  \n  Returns a list of all available mathematical constants.\n- `Formula.availableFunctions() : string[]`  \n  Returns a list of all supported mathematical function names.\n\n### Visualizer Class\n\nThe `Visualizer` class can be used independently for more control over AST visualization:\n\n- `new Visualizer()`\n- `visualize( node: ASTNode, options?: VisualizationOptions ) : string`\n\n## Supported Elements\n\nThe parser supports:\n- **Operators**: `=`, `==`, `!=`, `\u003c`, `\u003e`, `\u003c=`, `\u003e=`, `||`, `\u0026\u0026`, `+`, `-`, `*`, `/`, `%`, `^`, `!`\n- **Constants**: `pi`, `e`, `phi`, `sqrt2`, `sqrt3`, `sqrt5`, `infinity`\n- **Functions**: Wide range of math functions (`sin`, `cos`, `log`, `sqrt`, `integral`, `sum`, `product`, `derivative`, etc.)\n- **Complex Structures**: Matrices (`matrix(1, 2; 3, 4)`), Vectors (`[1, 2, 3]`), Ranges (`[0, 10]`)\n\n----\n\nCopyright (c) 2026 Paul Köhler (komed3). All rights reserved.  \nReleased under the MIT license. See LICENSE file in the project root for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkomed3%2Fmath-formula-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkomed3%2Fmath-formula-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkomed3%2Fmath-formula-parser/lists"}