Repository: aunyks/newton-api
Branch: master
Commit: f25c930bb2f9
Files: 7
Total size: 11.4 KB
Directory structure:
gitextract_rr_m6713/
├── .gitignore
├── README.md
├── lib/
│ └── operations.js
├── package.json
├── pages/
│ ├── api/
│ │ └── v2/
│ │ └── [operation]/
│ │ └── [data].js
│ └── index.js
└── test.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
# Logs
logs
*.log
npm-debug.log*
.next
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules
jspm_packages
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history
.vercel
================================================
FILE: README.md
================================================
# newton
## A really micro micro-service for advanced math.
Newton does anything from numerical calculation to symbolic math parsing.
### How does it work?
1. Send a GET request to newton with a url-encoded math expression and your preferred operation.
2. Get back a JSON response with your problem solved.
### Show me
Let's find the derivative of x^2.
So, we send a request to the newton url saying just that:
-> `https://newton.now.sh/api/v2/derive/x%5E2` (Note the url-encoded `^`)
Now, we get the following response:
```
{
"operation":"derive",
"expression":"x^2",
"result":"2 x"
}
```
It's that simple!
### Get Started
1. Send a GET request to newton.
```
https://newton.now.sh/api/v2/:operation/:expression
```
Note: `:operation` is the math operation that you want to perform. `:expression` is the *url-encoded* math expression on which you want to operate. **View available operation endpoints below!**
2. That's it! You'll be returned a JSON object with the operation you requested, the expression you provided, and the result of the operation performed on the expression.
### View available endpoints:
| Operation | API Endpoint | Result |
|:---------:|:-----------------:|:-----------------:|
| Simplify | /simplify/2^2+2(2)| 8 |
| Factor | /factor/x^2 + 2x | x (x + 2) |
| Derive | /derive/x^2+2x | 2 x + 2 |
| Integrate | /integrate/x^2+2x | 1/3 x^3 + x^2 + C |
| Find 0's | /zeroes/x^2+2x | [-2, 0] |
| Find Tangent| /tangent/2lx^3 | 12 x + -16 |
| Area Under Curve| /area/2:4lx^3| 60 |
| Cosine | /cos/pi | -1 |
| Sine | /sin/0 | 0 |
| Tangent | /tan/0 | 0 |
| Inverse Cosine | /arccos/1 | 0 |
| Inverse Sine | /arcsin/0 | 0 |
| Inverse Tangent | /arctan/0 | 0 |
| Absolute Value | /abs/-1 | 1 |
| Logarithm | /log/2l8 | 3 |
*Keep in mind:*
To find the tangent line of a function at a certain x value,
send the request as c|f(x) where c is the given x value and f(x) is the function expression, the separator is a vertical bar '|'. See the table above for an example request.
To find the area under a function, send the request as c:d|f(x) where c is the starting x value, d is the ending x value, and f(x) is the function under which you want the curve between the two x values.
To compute fractions, enter expressions as numerator(over)denominator. For example, to process 2/4 you must send in your expression as 2(over)4. The result expression will be in standard math notation (1/2, 3/4).
### What have people made?
Some cool apps and libraries made with Newton include the following:
- [Newton Bot](https://twitter.com/aunyks/status/813127765646082050) (Coming soon!)
- [Newton Python Wrapper](https://github.com/ilevn/aionewton)
- [Newton Clay Microservice](https://clay.run/services/nicoslepicos/newton-api)
- [PyNewtonMath](https://github.com/benpryke/PyNewtonMath) (Python 3 Wrapper)
- [NewtonMath.js](https://github.com/benpryke/NewtonMath.js) (Native Node.js Wrapper)
- [goNewton](https://github.com/Jay9596/goNewton) (GoLang Wrapper)
- [newtonmath](https://github.com/anaskhan96/newtonmath) (Rust Wrapper)
- [Newton Telegram Bot](https://t.me/sir_newton_bot)
- [Ming Newton](https://ming-newton.herokuapp.com)
- Hopefully more to come!
-----------------------------------------------------------------
Built using [metadelta](https://github.com/metadelta/metadelta-core).
## Want to support Newton development?
Shop [MEZCLA](https://mezcla.xyz)!
Licensed under the GNU GPLv3 license.
Copyright (C) 2016-2020 Gerald Nash
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
================================================
FILE: lib/operations.js
================================================
var metadelta = require('@metadelta/core');
module.exports = {
simplify: metadelta.simplify,
factor: metadelta.factor,
zeroes: metadelta.zeroes,
integrate: metadelta.integrate,
derive: metadelta.derive,
cos: metadelta.cos,
sin: metadelta.sin,
tan: metadelta.tan,
arccos: metadelta.arccos,
arcsin: metadelta.arcsin,
arctan: metadelta.arctan,
abs: metadelta.abs,
log: function(expression){
var base = expression.split('|')[0];
var arg = expression.split('|')[1];
return metadelta.log(base, arg);
},
tangent: function(expression){
var data = expression.split('|');
var at = parseInt(data[0]);
var f = data[1];
return metadelta.tangent(f, at);
},
area: function(expression){
var split = expression.split('|');
var f = split[1];
var from = split[0].split(':')[0];
var to = split[0].split(':')[1];
return '' + metadelta.areaUnder(f, { start: from, finish: to });
}
};
================================================
FILE: package.json
================================================
{
"name": "newton-api",
"version": "1.0.1",
"description": "A really micro micro-service for advanced math.",
"main": "app.js",
"scripts": {
"start": "next start",
"dev": "next",
"build": "next build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/aunyks/newton.git"
},
"keywords": [
"math",
"newton",
"calculus",
"algebra",
"geometry",
"theory"
],
"author": "Gerald Nash",
"license": "GPLv3",
"private": true,
"bugs": {
"url": "https://github.com/aunyks/newton/issues"
},
"homepage": "https://github.com/aunyks/newton#readme",
"dependencies": {
"@metadelta/core": "^1.1.2",
"express": "^4.14.1",
"next": "^9.5.3",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"devDependencies": {
"colors": "^1.1.2",
"request": "^2.79.0"
}
}
================================================
FILE: pages/api/v2/[operation]/[data].js
================================================
import operations from '../../../../lib/operations.js'
module.exports = (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
// Get the math function operation based
// on the operation that we're given
const f = operations[req.query.operation]
// If the url isn't malformed, send our response
// with an answer. If not, send an error response
if (f === undefined) {
res.statusCode = 400
res.json({
error: 'Unknown operation'
})
} else {
// Compute the requested calculation and respond.
// If we cannot compute it properly (error thrown),
// then tell the client
try {
// The result from passing the data parameter
// to the operation function
req.query.data = req.query.data.split('(over)').join('/')
const computation = f(req.query.data)
res.statusCode = 200
res.json({
operation: req.query.operation,
expression: req.query.data,
result: computation
})
} catch (err) {
// Record this error
console.error(err)
res.statusCode = 500
// Let the client know of our inability to
// perform the requested calculation
res.json({ error: 'Unable to perform calculation' })
}
}
}
================================================
FILE: pages/index.js
================================================
import Head from 'next/head'
export default function Index({ }) {
return (
<>
<Head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>newton</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" />
</Head>
<style global jsx>
{
` html,
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
font-family: 'Open Sans', sans-serif;
background-color: black;
color: white;
overflow: scroll;
}
#center {
width: 100%;
text-align: center;
margin-top: 10vh;
}
#center>h1 {
font-size: 35px;
}
#center>p {
font-size: 25px;
}
.code {
width: 42ex;
margin: 40px auto;
text-align: left;
}
.code>p {
padding-top: 40px;
text-align: center;
}
.code>p>a {
color: white;
}
.code>p>a:visited {
color: white;
}
pre {
text-align: left;
}
`}
</style>
<article id="center">
<h1>newton</h1>
<p>A really micro micro-service for advanced math.</p>
<div className="code">
Send this:<br />
<pre>
<a href="https://newton.now.sh/api/v2/factor/x^2-1" style={{ color: 'white', 'textDecoration': 'none' }} target="_blank">https://newton.now.sh/api/v2/factor/x^2-1</a>
</pre>
Get this:
<pre>{`
{
"operation":"factor",
"expression":"x^2 - 1",
"result":"(x - 1) (x + 1)"
}
`}
</pre>
<p><a href="https://github.com/aunyks/newton-api">See More</a></p>
<br />
Supported By:
<hr />
<a href="https://mezcla.xyz" style={{ fontWeight: 'bold', color: 'white', fontSize: '2.5em', textDecoration: 'none' }}>MEZCLA</a>
</div>
</article>
</>
)
}
================================================
FILE: test.js
================================================
var req = require('request');
var colors = require('colors');
// Start server
require('./app.js')
var newtonUrl = 'http://localhost:3000/';
function request(route, callback){
req(newtonUrl + route, function (error, response, body) {
var value = JSON.parse(body).result;
callback(value);
});
}
function assert(expected, route, name){
expected = JSON.stringify(expected);
request(route, function(result){
result = JSON.stringify(result);
if(expected !== result){
console.log(`Warning: ${name} did not pass test!`.yellow);
console.log(`Expected: ${expected}\nReceived: ${result}`.red);
} else {
console.log(`Test: ${name} passed test`.green);
}
});
}
// Assert that our functions give the proper output
// TODO: give functions more than one test case at a time
assert('2 x', 'simplify/x+x', 'Simplify');
assert('x (x + 2)', 'factor/x^2 + 2x', 'Factor');
assert('2 x + 2', 'derive/x^2 + 2x', 'Derive');
assert('1/3 x^3 + x^2', 'integrate/x^2 + 2x','Integrate');
assert([-2, 0], 'zeroes/x^2 + 2x', 'Zeroes');
assert('12 x + -16', 'tangent/2|x^3', 'Tangent');
assert('60', 'area/2:4|x^3', 'Area Under Curve');
assert('3', 'log/2|8', 'Logarithm');
gitextract_rr_m6713/ ├── .gitignore ├── README.md ├── lib/ │ └── operations.js ├── package.json ├── pages/ │ ├── api/ │ │ └── v2/ │ │ └── [operation]/ │ │ └── [data].js │ └── index.js └── test.js
SYMBOL INDEX (3 symbols across 2 files)
FILE: pages/index.js
function Index (line 2) | function Index({ }) {
FILE: test.js
function request (line 9) | function request(route, callback){
function assert (line 17) | function assert(expected, route, name){
Condensed preview — 7 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (12K chars).
[
{
"path": ".gitignore",
"chars": 593,
"preview": "# Logs\nlogs\n*.log\nnpm-debug.log*\n.next\n\n# Runtime data\npids\n*.pid\n*.seed\n\n# Directory for instrumented libs generated by"
},
{
"path": "README.md",
"chars": 4468,
"preview": "# newton\n## A really micro micro-service for advanced math.\nNewton does anything from numerical calculation to symbolic "
},
{
"path": "lib/operations.js",
"chars": 950,
"preview": "var metadelta = require('@metadelta/core');\n\nmodule.exports = {\n simplify: metadelta.simplify,\n factor: metadelta.fact"
},
{
"path": "package.json",
"chars": 863,
"preview": "{\n \"name\": \"newton-api\",\n \"version\": \"1.0.1\",\n \"description\": \"A really micro micro-service for advanced math.\",\n \"m"
},
{
"path": "pages/api/v2/[operation]/[data].js",
"chars": 1348,
"preview": "import operations from '../../../../lib/operations.js'\n\nmodule.exports = (req, res) => {\n res.setHeader('Access-Control"
},
{
"path": "pages/index.js",
"chars": 2129,
"preview": "import Head from 'next/head'\nexport default function Index({ }) {\n return (\n <>\n <Head>\n <meta charSet=\""
},
{
"path": "test.js",
"chars": 1290,
"preview": "var req = require('request'); \nvar colors = require('colors');\n\n// Start server\nrequire('./app.js')\n\nvar newtonUrl = "
}
]
About this extraction
This page contains the full source code of the aunyks/newton-api GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 7 files (11.4 KB), approximately 3.4k tokens, and a symbol index with 3 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.