UNPKG

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