NewtonMath.js is an ES2016 compliant JavaScript API wrapper providing full support for the newton micro-service, which is available on GitHub.
Newton does anything from numerical calculation to symbolic math parsing.
Using npm:
npm install newtonmath.js --save
NewtonMath.js is compatible with node 6.x and both CommonJS and AMD module specifications and can run in the browser. API calls are implemented asynchronously and the result is available as the most appropriate type via a callback.
See the newton API GitHub repo for the full list of endpoints.
newton = require('newtonmath.js');
newton.derive('x^2', r => console.log(r)); // -> '2 x'
newton.cos('pi', r => console.log(r)); // -> -1
newton.zeroes('x^2+2x', r => console.log(r)); // -> [-2, 0]
<!-- In <head> -->
<script src="newtonmath-min.js"></script>
<!-- In <body> or script file -->
<script>
NewtonMath.derive('x^2', r => console.log(r)); // -> '2 x'
</script>
In the same vein as jQuery's noConflict method, you can reset the NewtonMath
global to its value prior to loading the module.
newton = NewtonMath.noConflict();
The following methods take optional extra arguments for convenience. As per the API, if these are not specified they must be included before a horizontal bar '|'
in the expression for newton.
newton.log('2|8', r => console.log(r)); // -> 3
newton.log(8, 2, r => console.log(r)); // -> 3
newton.tangent('2|x^3', r => console.log(r)); // -> '12 x + -16'
newton.tangent('x^3', 2, r => console.log(r)); // -> '12 x + -16'
newton.area('2:4|x^3', r => console.log(r)); // -> 60
newton.area('x^3', 2, 4, r => console.log(r)); // -> 60
Build the minified file and source map with babili:
npm run-script build
Run tests with Jasmine:
npm test