{"id":27143431,"url":"https://github.com/craftsys/eval-num-expr","last_synced_at":"2025-04-08T08:40:31.065Z","repository":{"id":51292286,"uuid":"358648434","full_name":"craftsys/eval-num-expr","owner":"craftsys","description":"Evaluate Numerical Expressions in Javascript (\"25+3*22\")","archived":false,"fork":false,"pushed_at":"2021-05-25T11:59:34.000Z","size":803,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-10T11:29:21.392Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://craftsys.github.io/eval-num-expr/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/craftsys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-16T15:48:58.000Z","updated_at":"2021-05-25T11:59:17.000Z","dependencies_parsed_at":"2022-08-26T16:21:16.045Z","dependency_job_id":null,"html_url":"https://github.com/craftsys/eval-num-expr","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craftsys%2Feval-num-expr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craftsys%2Feval-num-expr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craftsys%2Feval-num-expr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craftsys%2Feval-num-expr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/craftsys","download_url":"https://codeload.github.com/craftsys/eval-num-expr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247806244,"owners_count":20999305,"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":"2025-04-08T08:40:30.363Z","updated_at":"2025-04-08T08:40:31.054Z","avatar_url":"https://github.com/craftsys.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Evaluate Numerical Expressions\n\n## Installation\n\n```\nnpm install --save eval-num-expr\n```\n\n## Usage\n\n```js\nimport evalExpr from \"eval-num-expr\";\n\nconst value = evalExpr(\"100 + 3 * 55 + 73 - 73 * 18%\");\n// value = 324.86\n\n// With Invalid Expressions handling\ntry {\n  const value = evalExpr(\"100 + (3 * 55\");\n} catch (e) {\n  // Will throw an exception for invalid expressions\n  console.error(e.message);\n}\n```\n\nYou can use basic operations (e.g. +, -, \\*, /, %, ^ etc.) in you expressions.\n\n### Examples\n\n- 175 + 40 + 18% = 253.7\n- 10 + (100 - 100 \\* 18%) \\* 5 + 40 / 20 = 422\n\n\u003e _NOTE_: Floating points must be handled carefully. Use `Number(\u003cnumber\u003e).toFixed(\u003cdigits\u003e)` to fix the digits after\n\u003e decimal point.\n\n## Api\n\n\u003e This package supports TypeScript.\n\n### evalExpr\n\nThis is the default and only export from this package.\n\n```typescript\n/**\n * Evaluate numeric mathematical expression\n * @param string expression - The expression to evaluate (\"24 + 65 * 3 - 48\")\n * @return number - The evaluated value.\n *\n * @throws Will throw an error if the expression in invalid.\n *\n * NOTE: When passing floating points, please handle the digits after decimal point\n * e.g. 2 - 1.1 leads to 0.8999999999999999 intead of .9\n */\nevalExpr(expressions: string)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcraftsys%2Feval-num-expr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcraftsys%2Feval-num-expr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcraftsys%2Feval-num-expr/lists"}