UNPKG

1.93 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.createParser = void 0;
7
8var _factory = require("../../utils/factory");
9
10var name = 'parser';
11var dependencies = ['typed', 'Parser'];
12var createParser =
13/* #__PURE__ */
14(0, _factory.factory)(name, dependencies, function (_ref) {
15 var typed = _ref.typed,
16 Parser = _ref.Parser;
17
18 /**
19 * Create a parser. The function creates a new `math.Parser` object.
20 *
21 * Syntax:
22 *
23 * math.parser()
24 *
25 * Examples:
26 *
27 * const parser = new math.parser()
28 *
29 * // evaluate expressions
30 * const a = parser.evaluate('sqrt(3^2 + 4^2)') // 5
31 * const b = parser.evaluate('sqrt(-4)') // 2i
32 * const c = parser.evaluate('2 inch in cm') // 5.08 cm
33 * const d = parser.evaluate('cos(45 deg)') // 0.7071067811865476
34 *
35 * // define variables and functions
36 * parser.evaluate('x = 7 / 2') // 3.5
37 * parser.evaluate('x + 3') // 6.5
38 * parser.evaluate('function f(x, y) = x^y') // f(x, y)
39 * parser.evaluate('f(2, 3)') // 8
40 *
41 * // get and set variables and functions
42 * const x = parser.get('x') // 7
43 * const f = parser.get('f') // function
44 * const g = f(3, 2) // 9
45 * parser.set('h', 500)
46 * const i = parser.evaluate('h / 2') // 250
47 * parser.set('hello', function (name) {
48 * return 'hello, ' + name + '!'
49 * })
50 * parser.evaluate('hello("user")') // "hello, user!"
51 *
52 * // clear defined functions and variables
53 * parser.clear()
54 *
55 * See also:
56 *
57 * evaluate, compile, parse
58 *
59 * @return {Parser} Parser
60 */
61 return typed(name, {
62 '': function _() {
63 return new Parser();
64 }
65 });
66});
67exports.createParser = createParser;
\No newline at end of file