help.js 2.2 KB

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