{"id":13760577,"url":"https://github.com/5anthosh/fcal","last_synced_at":"2025-12-30T00:56:33.411Z","repository":{"id":48186694,"uuid":"212022485","full_name":"5anthosh/fcal","owner":"5anthosh","description":"Extensive math expression evaluator library for JavaScript and Node.js","archived":false,"fork":false,"pushed_at":"2021-02-03T07:22:15.000Z","size":1354,"stargazers_count":111,"open_issues_count":2,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-25T08:26:09.387Z","etag":null,"topics":["calculator","formula-evaluation-engine","interpreter","javascript","math","math-expression-evaluator","percentage","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/fcal","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/5anthosh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-01T05:55:19.000Z","updated_at":"2025-01-12T07:06:35.000Z","dependencies_parsed_at":"2022-09-10T14:11:08.882Z","dependency_job_id":null,"html_url":"https://github.com/5anthosh/fcal","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5anthosh%2Ffcal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5anthosh%2Ffcal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5anthosh%2Ffcal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5anthosh%2Ffcal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/5anthosh","download_url":"https://codeload.github.com/5anthosh/fcal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253409897,"owners_count":21903986,"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":["calculator","formula-evaluation-engine","interpreter","javascript","math","math-expression-evaluator","percentage","typescript"],"created_at":"2024-08-03T13:01:13.350Z","updated_at":"2025-12-30T00:56:33.344Z","avatar_url":"https://github.com/5anthosh.png","language":"TypeScript","readme":"![iamg](https://raw.githubusercontent.com/5anthosh/fcal/assets/logo.png)\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2F5anthosh%2Ffcal.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2F5anthosh%2Ffcal?ref=badge_shield)\n[![Version](https://badgen.net/npm/v/fcal)](https://www.npmjs.com/package/fcal)\n[![License: MIT](https://badgen.net/npm/license/fcal)](https://github.com/5anthosh/fcal/blob/master/LICENSE)\n[![Hits](https://data.jsdelivr.com/v1/package/npm/fcal/badge)](https://www.jsdelivr.com/package/npm/fcal)\n[![Downloads](https://badgen.net/npm/dt/fcal)](https://www.npmjs.com/package/fcal)\n\n### 🏠 [Homepage](https://github.com/5anthosh/fcal/wiki)\n\n\u003e Fcaljs is an extensive math expression evaluator library for JavaScript and Node.js.\n\u003e Using fcal, you can perform basic arithmetic, percentage operations with precision.\n\u003e It features a flexible expression parser with a large set of built-in units, functions and constants.\n\u003e Inspired from [Soulver](https://soulver.app/)\n\n![Fcal gui](https://raw.githubusercontent.com/5anthosh/fcal/assets/fcal.png)\n\n## Features\n\n- Units\n- Variables\n- Functions\n\n\u003e Playground [Fcal GUI](https://github.com/5anthosh/fcal-gui), [Codepen](https://codepen.io/5anthosh/full/XWWdyMg) , [CLI](https://github.com/5anthosh/fcal-cli)\n\n## Example\n\n```js\nconst fcal = new Fcal();\n// New variable\nfcal.evaluate('radius : 23 m'); // 23 Meters\n\nfcal.evaluate('PI * radius ^ 2'); // 1661.9025137490006231 Meters\n\nfcal.evaluate('PI2 * radius'); // 144.51326206514 Meters\n\n// Predefined functions\nfcal.evaluate('log(23)'); // 1.3617278360175928789\n\n// Percentage\nfcal.evaluate('23 % of 1023'); // 235.29\n\nfcal.evaluate('200 sec + 120 %'); // 440 Seconds\n\n// Unit conversion\nfcal.evaluate('20 minutes + 34 day in sec'); // 2938800 Seconds\n\nfcal.evaluate('sin(PI)'); // -1.6167204971158028306e-24\n\n// Constants\nfcal.evaluate('E'); // 2.718281828459045235360287\n\n// Predefined units\nfcal.evaluate('speed = 20 kph'); // 20 km/h\n\nfcal.evaluate('speed in mps'); // 5.5555555555555555556 m/s\n\nfcal.evaluate('23 C add 123 F'); // 196.40000000000004 °F\n\nfcal.evaluate('1.2 nsec + 3 week in sec'); // 1814400.0000000012 Seconds\n\n// Various number system\nfcal.evaluate('0b1010011 day + 45'); // 128 Days\n\nfcal.evaluate('23.44 kmh in oct'); //  0o27.341217270243656051 km/h\n```\n\n## Install\n\n### Browser\n\nthe library is the single JavaScript file fcal.js (or minified, fcal.min.js).\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/fcal/dist/fcal.js\"\u003e\u003c/script\u003e\n```\n\n### With [NPM](https://www.npmjs.com/)\n\n```sh\n$ npm install --save fcal\n```\n\n```js\nconst { Fcal } = require('fcal');\n```\n\n## Use\n\n```js\nconst { Fcal } = require('fcal');\n\nconst fcal = new Fcal();\nvar value = fcal.evaluate('102 day in minutes + abs(-34 day) in sec');\n\nconsole.log(value); // 11750400 Seconds\n```\n\n### Percentage\n\n```js\nvar value = fcal.evaluate('27% of 230 cm');\nconsole.log(value); // 62.1 Centimeters\n```\n\nYou can perform general percentage operation with `+` , `-`\n\n```js\nvar value = fcal.evaluate('1024 m + 6.1%');\nconsole.log(value); // 1086.464 Meters\n```\n\nIf type of left and right hand side of `of` is same, then operation will return percentage\n\n```js\nvar value = fcal.evaluate('10 of 10.100');\nconsole.log(value); // % 99.009900990099009901\n```\n\n### Scales\n\nYou can use Thousand `k`, million `M` and billion `B` scales.\n\n```js\nvar value = Fcal.eval('-0x14 M');\nconsole.log(value); //-20000000\n```\n\n### Equality and comparison\n\n```js\nconsole.log(Fcal.eval('100 == 1230')); // false\nconsole.log(Fcal.eval('20 cm \u003c 1 m')); // true\nconsole.log(Fcal.eval('100 cm != 100 m')); // true\n```\n\nYou can use `===` to compare irrespective type of value\n\n```js\nconsole.log(Fcal.eval('100 C === 100 F')); // true\n```\n\n#### Ternary operator\n\n```js\nvar value = Fcal.eval('234 cm \u003e 1 m and true ? 34: 100');\nconsole.log(value); // 34\n```\n\n### Syntax errors\n\nFcal will throw exception if there is error with expression\n\nFor more error context, use _info_ method in _FcalError_\n\n```js\ntry {\n  var value = Fcal.eval('343 + 23.45E+*34');\n} catch (e) {\n  if (e instanceof FcalError) {\n    console.log(e.info());\n  }\n}\n\n/*\nerr: Expecting number after + but got '*'\n| 343 + 23.45E+*34\n| ......^^^^^^^\n*/\n```\n\n### Format\n\nFormat the results\n\n```js\nvar value = Fcal.eval('10345345.3454');\nconsole.log(value.toFormat()); // 10,345,345.3554\n```\n\n#### Strict mode\n\nBy default, fcal will not throw exception if you try to use operations between different types or different units\n\nBut with strict mode\n\n```js\nconst fcal = new Fcal();\nfcal.setStrict(true)\ntry {\n  var value = fcal.evaluate('23% + 34 cm + 1');\n} catch (e) {\n  if (e instanceof FcalError) {\n    console.log(e.info());\n  }\n\n/*\nerr: Unexpected '+' operation between different types (unit, number)\n| 23% + 34 cm + 1\n| ^^^^^^^^^^^^^^^\n*/\n```\n\n### Using expression\n\nYou can change state of expression , re evaluate it\n\n```js\nconst { Fcal } = require('fcal');\n\nconst exp = new Fcal().expression('PI * radius cm ^ 2');\n\nexp.setValues({ radius: 8 });\n\nconsole.log(exp.evaluate()); // 201.06192982974676726 Centimeters\n\nexp.setValues({ radius: 10 });\n\nconsole.log(exp.evaluate()); // 314.15926535897932385 Centimeters\n\nexp.setValues({ radius: Infinity });\n\nconsole.log(exp.evaluate()); // Infinity Centimeters\n```\n\n## 🤝 Contributing\n\nContributions, issues and feature requests are welcome!\u003cbr /\u003eFeel free to check [issues page](https://github.com/5anthosh/fcal/issues).\n\nTo contribute\n\n```sh\n$ git clone https://github.com/5anthosh/fcal\n```\n\n```sh\n$ npm install\n```\n\n### Run tests\n\n```sh\n$ npm test\n```\n\n## Author\n\n👤 **Santhosh Kumar**\n\n- Github: [@5anthosh](https://github.com/5anthosh)\n\n\u003ca href=\"https://www.buymeacoffee.com/5anthosh\" target=\"_blank\"\u003e\u003cimg src=\"https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png\" alt=\"Buy Me A Coffee\" style=\"height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;\" \u003e\u003c/a\u003e\n\n## 📝 License\n\nCopyright © 2019 [Santhosh Kumar](https://github.com/5anthosh).\u003cbr /\u003e\nThis project is [MIT](https://github.com/5anthosh/fcal/blob/master/LICENSE) licensed.\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2F5anthosh%2Ffcal.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2F5anthosh%2Ffcal?ref=badge_large)\n","funding_links":["https://www.buymeacoffee.com/5anthosh"],"categories":["Misc","Misc [🔝](#readme)","大杂烩"],"sub_categories":["Other","其它"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F5anthosh%2Ffcal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F5anthosh%2Ffcal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F5anthosh%2Ffcal/lists"}