UNPKG

mathjs

Version:

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser and offers an integrated solution to work with numbers, big numbers, complex numbers, units, and matrices.

51 lines (33 loc) 1.03 kB
# Function parse Parse an expression. Returns a node tree, which can be evaluated by invoking node.eval(); ## Syntax ```js parse(expr) parse(expr, options) parse([expr1, expr2, expr3, ...]) parse([expr1, expr2, expr3, ...], options) ``` ### Parameters Parameter | Type | Description --------- | ---- | ----------- `expr` | String &#124; String[] &#124; Matrix | Expression to be parsed `options` | {nodes: Object<String, Node>} | Available options: - `nodes` a set of custom nodes ### Returns Type | Description ---- | ----------- Node &#124; Node[] | node ## Examples ```js var node = parse('sqrt(3^2 + 4^2)'); node.compile(math).eval(); // 5 var scope = {a:3, b:4} var node = parse('a * b'); // 12 var code = node.compile(math); code.eval(scope); // 12 scope.a = 5; code.eval(scope); // 20 var nodes = math.parse(['a = 3', 'b = 4', 'a * b']); nodes[2].compile(math).eval(); // 12 ``` <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->