Comments (1)
math.js is the way to perform calculations, it can parse the expression for validity and then evaluate it. There are problems though:
-
on mobile keyboards for iphone, only a decimal is available in the numeric keypad.
-
validateMeasurement
will have to return a validity flag, along with the validated measurement value. TheonChange*
import { parse, evaluate } from 'mathjs'; ... // TODO: mathematical expressions (only allow +, -, *, / symbols) keyed on = as input? function validateMeasurement(event) { var valid = true; // output 1 var value = event.target.value; // output 2 function parseValue(value) { ... // do math if string contains math operations if (value.match(/\d+\+$/)) { // e.g. 2+ valid = false; value = value; console.log("plus"); return { valid, value }; } try { parse(value); valid = true; value = evaluate(value); return { valid, value }; } catch (ex) { console.log("Not a mathematical expression."); }
const onChangeMM = (event) => { let {valid, value} = validateMeasurement(event) if (!valid) { setMM({ ...millimeters, input: value, output: "", error: "" }); return; }
-
once we detect a mathematical expression is being input, we have to provide a calculate button to let the user tell us when they're done formatting the equation. A good example expression would be adding three measurements :
1 + 1.5 + 3+(5/8)
from divisor.
Related Issues (6)
- Project Initialization HOT 2
- Full Stack Web App Initialization HOT 2
- Algorithm Development HOT 3
- Webpack Optimization HOT 2
- Feature Brainstorming HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from divisor.