
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
@artginzburg/calc
Advanced tools
The calc
function takes a string argument and returns the value of the resulting calculation.
npm install @motardo/calc
var calc = require("@motardo/calc");
calc("1+2") // 3
calc("-1 / 2") // -0.5
calc("2 + 3 * 4") // 14
calc("(2+3)*4") // 20
calc("5^2") // 25
Try it out at https://motardo.github.io/calc/web/index.html
Run the tests with:
npm test
calc uses the shunting yard algorithm and two separate stacks, one for numerical values, and one for operators. The operators currently supported are + - * / and ^. Parenthesis can be used to override operator precedence.
1e9
for 1 billionlog
and ln
notationBug reports and contributions are welcome. Open an issue on github or email the author at nswilson@gmail.com
FAQs
Evaluate mathematical expressions
We found that @artginzburg/calc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.