forked from josdejong/mathjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp.js
More file actions
65 lines (60 loc) · 1.93 KB
/
help.js
File metadata and controls
65 lines (60 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { factory } from '../../utils/factory.js'
import { getSafeProperty } from '../../utils/customs.js'
import { embeddedDocs } from '../embeddedDocs/embeddedDocs.js'
import { hasOwnProperty } from '../../utils/object.js'
const name = 'help'
const dependencies = ['typed', 'mathWithTransform', 'Help']
export const createHelp = /* #__PURE__ */ factory(name, dependencies, ({ typed, mathWithTransform, Help }) => {
/**
* 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 (search) {
let prop
let 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
}
}
}
}
*/
}
const doc = getSafeProperty(embeddedDocs, searchName)
if (!doc) {
const searchText = typeof searchName === 'function' ? searchName.name : searchName
throw new Error('No documentation found on "' + searchText + '"')
}
return new Help(doc)
}
})
})