UNPKG

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