index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. var docs = require('./globals-docs.json');
  2. /**
  3. * Docs: an object of documentation as a plain-old-javascript object.
  4. *
  5. * Has keys that correspond to environments:
  6. *
  7. * - builtin
  8. * - nonstandard
  9. * - browser
  10. * - worker
  11. * - node
  12. */
  13. module.exports.docs = docs;
  14. function buildLowerCased() {
  15. var lowercased = {};
  16. for (var k in docs) {
  17. lowercased[k] = {};
  18. for (var name in docs[k]) {
  19. lowercased[k][name.toLowerCase()] = docs[k][name];
  20. }
  21. }
  22. return lowercased;
  23. }
  24. var lowerCased = buildLowerCased();
  25. /**
  26. * Lowercased docs: the same as the original docs array, but with lowercased
  27. * names.
  28. */
  29. module.exports.lowerCased = lowerCased;
  30. /**
  31. * Get a URL for a global object.
  32. *
  33. * @param {string} name name of the global object
  34. * @param {Array<string>} env environments that will be reached. By default tries all environments
  35. * @returns {string|undefined} the URL of the documentation resource, if found
  36. * @example
  37. * getDoc('Array'); // yields MDC documentation for Array
  38. */
  39. module.exports.getDoc = function(name, env) {
  40. if (!env) env = Object.keys(lowerCased);
  41. for (var i = 0; i < env.length; i++) {
  42. var d = lowerCased[env[i]][name.toLowerCase()];
  43. if (d) return d;
  44. }
  45. };