feat:node-modules
This commit is contained in:
54
node_modules/mathjs/lib/esm/expression/function/compile.js
generated
vendored
Normal file
54
node_modules/mathjs/lib/esm/expression/function/compile.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import { deepMap } from '../../utils/collection.js';
|
||||
import { factory } from '../../utils/factory.js';
|
||||
var name = 'compile';
|
||||
var dependencies = ['typed', 'parse'];
|
||||
export var createCompile = /* #__PURE__ */factory(name, dependencies, _ref => {
|
||||
var {
|
||||
typed,
|
||||
parse
|
||||
} = _ref;
|
||||
/**
|
||||
* Parse and compile an expression.
|
||||
* Returns a an object with a function `evaluate([scope])` to evaluate the
|
||||
* compiled expression.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.compile(expr) // returns one node
|
||||
* math.compile([expr1, expr2, expr3, ...]) // returns an array with nodes
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* const code1 = math.compile('sqrt(3^2 + 4^2)')
|
||||
* code1.evaluate() // 5
|
||||
*
|
||||
* let scope = {a: 3, b: 4}
|
||||
* const code2 = math.compile('a * b') // 12
|
||||
* code2.evaluate(scope) // 12
|
||||
* scope.a = 5
|
||||
* code2.evaluate(scope) // 20
|
||||
*
|
||||
* const nodes = math.compile(['a = 3', 'b = 4', 'a * b'])
|
||||
* nodes[2].evaluate() // 12
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* parse, evaluate
|
||||
*
|
||||
* @param {string | string[] | Array | Matrix} expr
|
||||
* The expression to be compiled
|
||||
* @return {{evaluate: Function} | Array.<{evaluate: Function}>} code
|
||||
* An object with the compiled expression
|
||||
* @throws {Error}
|
||||
*/
|
||||
return typed(name, {
|
||||
string: function string(expr) {
|
||||
return parse(expr).compile();
|
||||
},
|
||||
'Array | Matrix': function Array__Matrix(expr) {
|
||||
return deepMap(expr, function (entry) {
|
||||
return parse(entry).compile();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
68
node_modules/mathjs/lib/esm/expression/function/evaluate.js
generated
vendored
Normal file
68
node_modules/mathjs/lib/esm/expression/function/evaluate.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
import { deepMap } from '../../utils/collection.js';
|
||||
import { factory } from '../../utils/factory.js';
|
||||
import { createEmptyMap } from '../../utils/map.js';
|
||||
var name = 'evaluate';
|
||||
var dependencies = ['typed', 'parse'];
|
||||
export var createEvaluate = /* #__PURE__ */factory(name, dependencies, _ref => {
|
||||
var {
|
||||
typed,
|
||||
parse
|
||||
} = _ref;
|
||||
/**
|
||||
* Evaluate an expression.
|
||||
*
|
||||
* The expression parser does not use JavaScript. Its syntax is close
|
||||
* to JavaScript but more suited for mathematical expressions.
|
||||
* See [https://mathjs.org/docs/expressions/syntax.html](https://mathjs.org/docs/expressions/syntax.html) to learn
|
||||
* the syntax and get an overview of the exact differences from JavaScript.
|
||||
*
|
||||
* Note the evaluating arbitrary expressions may involve security risks,
|
||||
* see [https://mathjs.org/docs/expressions/security.html](https://mathjs.org/docs/expressions/security.html) for more information.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.evaluate(expr)
|
||||
* math.evaluate(expr, scope)
|
||||
* math.evaluate([expr1, expr2, expr3, ...])
|
||||
* math.evaluate([expr1, expr2, expr3, ...], scope)
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* math.evaluate('(2+3)/4') // 1.25
|
||||
* math.evaluate('sqrt(3^2 + 4^2)') // 5
|
||||
* math.evaluate('sqrt(-4)') // 2i
|
||||
* math.evaluate(['a=3', 'b=4', 'a*b']) // [3, 4, 12]
|
||||
*
|
||||
* let scope = {a:3, b:4}
|
||||
* math.evaluate('a * b', scope) // 12
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* parse, compile
|
||||
*
|
||||
* @param {string | string[] | Matrix} expr The expression to be evaluated
|
||||
* @param {Object} [scope] Scope to read/write variables
|
||||
* @return {*} The result of the expression
|
||||
* @throws {Error}
|
||||
*/
|
||||
return typed(name, {
|
||||
string: function string(expr) {
|
||||
var scope = createEmptyMap();
|
||||
return parse(expr).compile().evaluate(scope);
|
||||
},
|
||||
'string, Map | Object': function string_Map__Object(expr, scope) {
|
||||
return parse(expr).compile().evaluate(scope);
|
||||
},
|
||||
'Array | Matrix': function Array__Matrix(expr) {
|
||||
var scope = createEmptyMap();
|
||||
return deepMap(expr, function (entry) {
|
||||
return parse(entry).compile().evaluate(scope);
|
||||
});
|
||||
},
|
||||
'Array | Matrix, Map | Object': function Array__Matrix_Map__Object(expr, scope) {
|
||||
return deepMap(expr, function (entry) {
|
||||
return parse(entry).compile().evaluate(scope);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
66
node_modules/mathjs/lib/esm/expression/function/help.js
generated
vendored
Normal file
66
node_modules/mathjs/lib/esm/expression/function/help.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
import { factory } from '../../utils/factory.js';
|
||||
import { getSafeProperty } from '../../utils/customs.js';
|
||||
import { embeddedDocs } from '../embeddedDocs/embeddedDocs.js';
|
||||
import { hasOwnProperty } from '../../utils/object.js';
|
||||
var name = 'help';
|
||||
var dependencies = ['typed', 'mathWithTransform', 'Help'];
|
||||
export var createHelp = /* #__PURE__ */factory(name, dependencies, _ref => {
|
||||
var {
|
||||
typed,
|
||||
mathWithTransform,
|
||||
Help
|
||||
} = _ref;
|
||||
/**
|
||||
* Retrieve help on a function or data type.
|
||||
* Help files are retrieved from the embedded documentation in math.docs.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.help(search)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* console.log(math.help('sin').toString())
|
||||
* console.log(math.help(math.add).toString())
|
||||
* console.log(math.help(math.add).toJSON())
|
||||
*
|
||||
* @param {Function | string | Object} search A function or function name
|
||||
* for which to get help
|
||||
* @return {Help} A help object
|
||||
*/
|
||||
return typed(name, {
|
||||
any: function any(search) {
|
||||
var prop;
|
||||
var searchName = search;
|
||||
if (typeof search !== 'string') {
|
||||
for (prop in mathWithTransform) {
|
||||
// search in functions and constants
|
||||
if (hasOwnProperty(mathWithTransform, prop) && search === mathWithTransform[prop]) {
|
||||
searchName = prop;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: implement help for data types
|
||||
if (!text) {
|
||||
// search data type
|
||||
for (prop in math.type) {
|
||||
if (hasOwnProperty(math, prop)) {
|
||||
if (search === math.type[prop]) {
|
||||
text = prop
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
var doc = getSafeProperty(embeddedDocs, searchName);
|
||||
if (!doc) {
|
||||
var searchText = typeof searchName === 'function' ? searchName.name : searchName;
|
||||
throw new Error('No documentation found on "' + searchText + '"');
|
||||
}
|
||||
return new Help(doc);
|
||||
}
|
||||
});
|
||||
});
|
||||
57
node_modules/mathjs/lib/esm/expression/function/parser.js
generated
vendored
Normal file
57
node_modules/mathjs/lib/esm/expression/function/parser.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
import { factory } from '../../utils/factory.js';
|
||||
var name = 'parser';
|
||||
var dependencies = ['typed', 'Parser'];
|
||||
export var createParser = /* #__PURE__ */factory(name, dependencies, _ref => {
|
||||
var {
|
||||
typed,
|
||||
Parser
|
||||
} = _ref;
|
||||
/**
|
||||
* Create a parser. The function creates a new `math.Parser` object.
|
||||
*
|
||||
* Syntax:
|
||||
*
|
||||
* math.parser()
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* const parser = new math.parser()
|
||||
*
|
||||
* // evaluate expressions
|
||||
* const a = parser.evaluate('sqrt(3^2 + 4^2)') // 5
|
||||
* const b = parser.evaluate('sqrt(-4)') // 2i
|
||||
* const c = parser.evaluate('2 inch in cm') // 5.08 cm
|
||||
* const d = parser.evaluate('cos(45 deg)') // 0.7071067811865476
|
||||
*
|
||||
* // define variables and functions
|
||||
* parser.evaluate('x = 7 / 2') // 3.5
|
||||
* parser.evaluate('x + 3') // 6.5
|
||||
* parser.evaluate('f(x, y) = x^y') // f(x, y)
|
||||
* parser.evaluate('f(2, 3)') // 8
|
||||
*
|
||||
* // get and set variables and functions
|
||||
* const x = parser.get('x') // 3.5
|
||||
* const f = parser.get('f') // function
|
||||
* const g = f(3, 2) // 9
|
||||
* parser.set('h', 500)
|
||||
* const i = parser.evaluate('h / 2') // 250
|
||||
* parser.set('hello', function (name) {
|
||||
* return 'hello, ' + name + '!'
|
||||
* })
|
||||
* parser.evaluate('hello("user")') // "hello, user!"
|
||||
*
|
||||
* // clear defined functions and variables
|
||||
* parser.clear()
|
||||
*
|
||||
* See also:
|
||||
*
|
||||
* evaluate, compile, parse
|
||||
*
|
||||
* @return {Parser} Parser
|
||||
*/
|
||||
return typed(name, {
|
||||
'': function _() {
|
||||
return new Parser();
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user