2.2.0 • Published 5 years ago
evaluatex v2.2.0
Evaluatex
Evaluatex is a parser that reads and evaluates LaTeX and ASCII math. Use in Node, Angular, or with vanilla Javascript on both clients and servers.
Evaluatex can safely resolve math without relying Javascript's native eval() function. It can also support custom variables and functions, so you can pass in arbitrary values without having to hard-code the math.
Evaluatex is reasonably stable. It has been tested for common patterns and use cases, but when provoked it may do weird and unexpected things such as eating your cat.
Installation
npm install evaluatex
# or
yarn install/add evaluatexconst evaluatex = require("evaluatex");
// or
import evaluatex from "evaluatex";Building
Get yarn and do yarn install.
yarn build transpiles ES6 sources to dist/.
yarn test runs tests in the test/ directory.
API
const fn = evaluatex(expression, constants = {}, options = {});
const result = fn(variables = {});evaluatex()compiles a text math expression into a functionfn.expressionis an ASCII or LaTeX expression to be parsed and evaluated.constantsis a map of constant values - values that don't change if you invokefnmore than once.optionsis a map of options for the compiler.
resultis the numerical result of the calculation.variablesis a map of variables that can change between invocations.
Features and usage
A complete manual is available on the project page.