Homepage
🏠Fcaljs is an extensive math expression evaluator library for JavaScript and Node.js. Using fcal, you can perform basic arithmetic, percentage operations with precision. It features a flexible expression parser with a large set of built-in units, functions and constants. Inspired from Numi
Features
- Units
- Variables
- Functions
Example
const fcal = ;// New variablefcal; // 23 Meters fcal; // 1661.9025137490006231 Meters fcal; // 144.51326206514 Meters // Predefined functionsfcal; // 1.3617278360175928789 // Percentagefcal; // 235.29 fcal; // 440 Seconds // Unit conversionfcal; // 2938800 Seconds fcal; // -1.6167204971158028306e-24 // Constantsfcal; // 2.718281828459045235360287 // Predefined unitsfcal; // 20 km/h fcal; // 5.5555555555555555556 m/s fcal; // 196.40000000000004 °F fcal; // 1814400.0000000012 Seconds // Various number systemfcal; // 128 Days fcal; // 0o27.341217270243656051 km/h
Install
Browser
the library is the single JavaScript file fcal.js (or minified, fcal.min.js).
NPM
With$ npm install --save fcal
const Fcal = ;
Use
const Fcal = ; const fcal = ;var value = fcal; console; // 11750400 Seconds
Percentage
var value = fcal;console; // 62.1 Centimeters
You can perform general percentage operation with +
, -
var value = fcal;console; // 1086.464 Meters
If type of left and right hand side of of
is same, then operation will return percentage
var value = fcal;console; // % 99.009900990099009901
Scales
You can use Thousand k
, million M
and billion B
scales.
var value = Fcal;console; //-20000000
Equality and comparison
console; // falseconsole; // trueconsole; // true
You can use ===
to compare irrespective type of value
console; // true
Ternary operator
var value = Fcal;console; // 34
Syntax errors
Fcal will throw exception if there is error with expression
For more error context, use info method in FcalError
try var value = Fcal; catch e if e instanceof FcalError console; /*err: Expecting number after + but got '*'| 343 + 23.45E+*34| ......^^^^^^^*/
Strict mode
By default, fcal will not throw exception if you try to use operations between different types or different units
But with strict mode
const fcal = ;fcaltry var value = fcal; catch e if e instanceof FcalError console; /*err: Unexpected '+' operation between different types (unit, number)| 23% + 34 cm + 1| ^^^^^^^^^^^^^^^*/
Using expression
You can change state of expression , re evaluate it
const Fcal = ; const exp = ; exp; console; // 201.06192982974676726 Centimeters exp; console; // 314.15926535897932385 Centimeters exp; console; // Infinity Centimeters
🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
To contribute
$ git clone https://github.com/5anthosh/fcal
$ npm install
Run tests
$ npm test
Author
👤 Santhosh Kumar
- Github: @5anthosh
📝 License
Copyright © 2019 Santhosh Kumar.
This project is MIT licensed.