1 | import { factory } from '../../utils/factory.js';
|
2 | import { getSafeProperty } from '../../utils/customs.js';
|
3 | import { embeddedDocs } from '../embeddedDocs/embeddedDocs.js';
|
4 | import { hasOwnProperty } from '../../utils/object.js';
|
5 | var name = 'help';
|
6 | var dependencies = ['typed', 'mathWithTransform', 'Help'];
|
7 | export var createHelp = /* #__PURE__ */factory(name, dependencies, _ref => {
|
8 | var {
|
9 | typed,
|
10 | mathWithTransform,
|
11 | Help
|
12 | } = _ref;
|
13 |
|
14 | /**
|
15 | * Retrieve help on a function or data type.
|
16 | * Help files are retrieved from the embedded documentation in math.docs.
|
17 | *
|
18 | * Syntax:
|
19 | *
|
20 | * math.help(search)
|
21 | *
|
22 | * Examples:
|
23 | *
|
24 | * console.log(math.help('sin').toString())
|
25 | * console.log(math.help(math.add).toString())
|
26 | * console.log(math.help(math.add).toJSON())
|
27 | *
|
28 | * @param {Function | string | Object} search A function or function name
|
29 | * for which to get help
|
30 | * @return {Help} A help object
|
31 | */
|
32 | return typed(name, {
|
33 | any: function any(search) {
|
34 | var prop;
|
35 | var searchName = search;
|
36 |
|
37 | if (typeof search !== 'string') {
|
38 | for (prop in mathWithTransform) {
|
39 | // search in functions and constants
|
40 | if (hasOwnProperty(mathWithTransform, prop) && search === mathWithTransform[prop]) {
|
41 | searchName = prop;
|
42 | break;
|
43 | }
|
44 | }
|
45 | /* TODO: implement help for data types
|
46 | if (!text) {
|
47 | // search data type
|
48 | for (prop in math.type) {
|
49 | if (hasOwnProperty(math, prop)) {
|
50 | if (search === math.type[prop]) {
|
51 | text = prop
|
52 | break
|
53 | }
|
54 | }
|
55 | }
|
56 | }
|
57 | */
|
58 |
|
59 | }
|
60 |
|
61 | var doc = getSafeProperty(embeddedDocs, searchName);
|
62 |
|
63 | if (!doc) {
|
64 | var searchText = typeof searchName === 'function' ? searchName.name : searchName;
|
65 | throw new Error('No documentation found on "' + searchText + '"');
|
66 | }
|
67 |
|
68 | return new Help(doc);
|
69 | }
|
70 | });
|
71 | }); |
\ | No newline at end of file |