{"id":15651577,"url":"https://github.com/kennethanceyer/metric-parser","last_synced_at":"2026-04-12T18:31:11.301Z","repository":{"id":5889033,"uuid":"54097530","full_name":"KennethanCeyer/metric-parser","owner":"KennethanCeyer","description":":scroll: AST-based advanced mathematical parser written by Typescript.","archived":false,"fork":false,"pushed_at":"2023-02-09T22:02:35.000Z","size":1871,"stargazers_count":34,"open_issues_count":13,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-27T06:51:39.278Z","etag":null,"topics":["ast","expression","javascript","metirc-parser","parser","syntax-tree","tree"],"latest_commit_sha":null,"homepage":"http://www.pigno.se/barn/PIGNOSE-FormulaParser/","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/KennethanCeyer.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":"2016-03-17T07:28:24.000Z","updated_at":"2024-12-12T12:25:51.000Z","dependencies_parsed_at":"2024-06-19T05:18:58.337Z","dependency_job_id":"c7e3e68c-f8bc-48f7-8471-c6be4d69ad6b","html_url":"https://github.com/KennethanCeyer/metric-parser","commit_stats":null,"previous_names":["kennethanceyer/formulaparser"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KennethanCeyer%2Fmetric-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KennethanCeyer%2Fmetric-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KennethanCeyer%2Fmetric-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KennethanCeyer%2Fmetric-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KennethanCeyer","download_url":"https://codeload.github.com/KennethanCeyer/metric-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251099735,"owners_count":21536153,"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":["ast","expression","javascript","metirc-parser","parser","syntax-tree","tree"],"created_at":"2024-10-03T12:39:10.771Z","updated_at":"2025-12-12T04:31:55.744Z","avatar_url":"https://github.com/KennethanCeyer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg width=\"200\" src=\"https://www.pigno.se/static/assets/images/metric-parser-logo.svg\" /\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003ca href=\"https://nodei.co/npm/metric-parser/\"\u003e\u003cimg src=\"https://nodei.co/npm/metric-parser.png\" alt=\"NPM\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://badge.fury.io/js/metric-parser\"\u003e\u003cimg src=\"https://badge.fury.io/js/metric-parser.svg\" alt=\"npm version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://gitter.im/KennethanCeyer/PIGNOSE?utm_source=badge\u0026amp;utm_medium=badge\u0026amp;utm_campaign=pr-badge\u0026amp;utm_content=badge\"\u003e\u003cimg src=\"https://badges.gitter.im/Join%20Chat.svg\" alt=\"Join the chat at https://gitter.im/KennethanCeyer/PIGNOSE\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/KennethanCeyer/metric-parser\"\u003e\u003cimg src=\"https://img.shields.io/github/stars/KennethanCeyer/metric-parser.svg\" alt=\"GitHub stars\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/KennethanCeyer/metric-parser/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/KennethanCeyer/metric-parser.svg\" alt=\"GitHub license\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://travis-ci.org/KennethanCeyer/metric-parser\"\u003e\u003cimg src=\"https://travis-ci.org/KennethanCeyer/metric-parser.svg?branch=master\" alt=\"Build Status\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://coveralls.io/github/KennethanCeyer/metric-parser\"\u003e\u003cimg src=\"https://coveralls.io/repos/github/KennethanCeyer/metric-parser/badge.svg\" alt=\"Coverage Status\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/KennethanCeyer/metric-parser\"\u003e\u003cimg src=\"https://codecov.io/gh/KennethanCeyer/metric-parser/branch/master/graph/badge.svg\" alt=\"codecov\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://codeclimate.com/github/KennethanCeyer/metric-parser/maintainability\"\u003e\u003cimg src=\"https://api.codeclimate.com/v1/badges/c69ae53f077a68618867/maintainability\" alt=\"Maintainability\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://codeclimate.com/github/KennethanCeyer/metric-parser/test_coverage\"\u003e\u003cimg src=\"https://api.codeclimate.com/v1/badges/c69ae53f077a68618867/test_coverage\" alt=\"Test Coverage\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.codefactor.io/repository/github/kennethanceyer/metric-parser\"\u003e\u003cimg src=\"https://www.codefactor.io/repository/github/kennethanceyer/metric-parser/badge\" alt=\"CodeFactor\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n----\n\n### Special lovers :heart:\n\n- [rhyscitlema.com](http://rhyscitlema.com/algorithms/expression-parsing-algorithm)\n- [Precedence climbing](http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm#climbing)\n\n----\n\n### :clap: Example\n\n[See demo](http://www.pigno.se/barn/PIGNOSE-FormulaParser/)\n\n![Screen Shot](http://www.pigno.se/barn/PIGNOSE-FormulaParser/demo/img/screenshot_main.png)\n\n----\n\n### :package: Installation\n\n#### git\n\n```bash\n$ git clone git@github.com:KennethanCeyer/metric-parser.git\n```\n\n#### npm\n\n```bash\n$ npm install metric-parser\n```\n\n#### yarn\n\n```bash\n$ yarn add metric-parser\n```\n\n----\n\n### :page_with_curl: Getting started\n\n#### Javascript (Web)\n\n```html\n\u003cscript src=\"~/dist/metric.parser.umd.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n// { data: {tree object}, code: 0 }\nconst result = metricParser.convert('1 + (2 + 3)');\n\n// { data: [ 1, '+', 2, '+', 3 ], code: 0 } \u003c= bracket will be optimized\nconst expression = metricParser.convert(result.data);\n\n// true | false \u003c= true means valid\nconst valid = metricParser.valid(result.data);\n\u003c/script\u003e\n```\n\n#### Typescript\n```typescript\nimport { convert, valid } from 'metric-parser';\n\n// { data: {tree object}, code: 0 }\nconst result: ParserGeneralResult = convert('1 + (2 + 3)');\n\n// { data: [ 1, '+', 2, '+', 3 ], code: 0 } \u003c= bracket will be optimized\nconst expression: string[] = convert(result.data);\n\n// true | false \u003c= true means valid\nconst valid: boolean = valid(result.data);\n```\n\n#### NodeJS\n\n```javascript\nconst parser = require('metric-parser');\n\n// { data: {tree object}, code: 0 }\nconst result = parser.convert('1 + (2 + 3)');\n\n// { data: [ 1, '+', 2, '+', 3 ], code: 0 } \u003c= bracket will be optimized\nconst expression = parser.convert(result.data);\n\n// true | false \u003c= true means valid\nconst valid = parser.valid(result.data);\n```\n\n----\n\n### :zap: Type\n\n#### Tree\n\u003e Tree is a simple object that converted from AST. \n\n```typescript\nconst result = convert('1 + (2 + 3)');\nconst tree: Tree = result.data;\n```\n\n```javascript\n{\n  operator: '+',\n  operand1: { value: { type: 'unit', unit: 1 } },\n  operand2: {\n    operator: '+',\n    operand1: { value: { type: 'unit', unit: 2 } },\n    operand1: { value: { type: 'unit', unit: 3 } }\n  }\n}\n```\n\n#### AST (AbstractSyntaxTree)\n\u003e AST is the most important object that contains the structure of a formula.\n\n```typescript\nconst ast = convert('1 + (2 + 3)', true);\n\n```\n\n```typescript\n{\n  AbstractSyntaxTree {\n    type: 1, // operator\n    value: '+',\n    leftNode: AbstractSyntaxTree {\n      type: 2, // value\n      value: 1\n    },\n    rightNode: AbstractSyntaxTree {\n      type: 1, // operator\n      value: '+',\n      leftNode: AbstractSyntaxTree {\n        type: 1, // value\n        value: 2\n      },\n      rightNode: AbstractSyntaxTree {\n        type: 1, // value,\n        value: 3\n      }\n    }\n  }\n}\n```\n\n----\n\n### :triangular_flag_on_post: Roadmap\n\n**v0.0.1**\n\n- [x] support typescript\n- [x] support UMD and ES5 module\n- [x] support automated test environment\n- [x] support custom value (custom object as value)\n- [x] support implicit patterns (multiplication omitted, operator aliases)\n- [x] support reference docs\n- [x] improve parser logic based [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree)\n- [x] improve validation error (parserStack, codes)\n- [x] add unit test with coverage rate over 90%\n- [x] support validation for many cases\n\n**v0.1.0**\n\n- [ ] guidelines for developers\n- [ ] guidelines for contributors\n\n**v0.2.0**\n\n- [ ] function expression `IF()`, `SUM()`, `AVG()`, `_CUSTOM_NAMED_FUNC_()`\n- [ ] support custom tree model declaration\n\n**v0.3.0**\n\n- [ ] declare variable (operator and value type)\n\n----\n\n### :mag: License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FKennethanCeyer%2Fmetric-parser.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FKennethanCeyer%2Fmetric-parser?ref=badge_large)\n\nThe MIT License (MIT)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkennethanceyer%2Fmetric-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkennethanceyer%2Fmetric-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkennethanceyer%2Fmetric-parser/lists"}