-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
51 lines (45 loc) · 1.23 KB
/
index.js
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
var docs = require('./globals-docs.json');
/**
* Docs: an object of documentation as a plain-old-javascript object.
*
* Has keys that correspond to environments:
*
* - builtin
* - nonstandard
* - browser
* - worker
* - node
*/
module.exports.docs = docs;
function buildLowerCased() {
var lowercased = {};
for (var k in docs) {
lowercased[k] = {};
for (var name in docs[k]) {
lowercased[k][name.toLowerCase()] = docs[k][name];
}
}
return lowercased;
}
var lowerCased = buildLowerCased();
/**
* Lowercased docs: the same as the original docs array, but with lowercased
* names.
*/
module.exports.lowerCased = lowerCased;
/**
* Get a URL for a global object.
*
* @param {string} name name of the global object
* @param {Array<string>} env environments that will be reached. By default tries all environments
* @returns {string|undefined} the URL of the documentation resource, if found
* @example
* getDoc('Array'); // yields MDC documentation for Array
*/
module.exports.getDoc = function(name, env) {
if (!env) env = Object.keys(lowerCased);
for (var i = 0; i < env.length; i++) {
var d = lowerCased[env[i]][name.toLowerCase()];
if (d) return d;
}
};