Skip to content

Commit 5f6359c

Browse files
committed
Document and add getter
1 parent 8a5eea2 commit 5f6359c

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
11
# globals-docs
22

33
Documentation URIs for JavaScript globals.
4+
5+
## `docs`
6+
7+
Docs: an object of documentation as a plain-old-javascript object.
8+
9+
Has keys that correspond to environments:
10+
11+
- builtin
12+
- nonstandard
13+
- browser
14+
- worker
15+
- node
16+
17+
18+
19+
20+
21+
## `getDoc`
22+
23+
Get a URL for a global object.
24+
25+
### Parameters
26+
27+
| name | type | description |
28+
| ---- | ---- | ----------- |
29+
| `name` | `string` | name of the global object |
30+
| `env` | `Array<string>` | environments that will be reached. By default tries all environments |
31+
32+
33+
### Examples
34+
35+
```js
36+
getDoc('Array'); // yields MDC documentation for Array
37+
```
38+
39+
Returns the URL of the documentation resource, if found

index.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,32 @@
1-
module.exports = require('./globals-docs.json');
1+
var docs = require('./globals-docs.json');
2+
3+
/**
4+
* Docs: an object of documentation as a plain-old-javascript object.
5+
*
6+
* Has keys that correspond to environments:
7+
*
8+
* - builtin
9+
* - nonstandard
10+
* - browser
11+
* - worker
12+
* - node
13+
*/
14+
module.exports.docs = docs;
15+
16+
/**
17+
* Get a URL for a global object.
18+
*
19+
* @param {string} name name of the global object
20+
* @param {Array<string>} env environments that will be reached. By default tries all environments
21+
* @returns {string|undefined} the URL of the documentation resource, if found
22+
* @example
23+
* getDoc('Array'); // yields MDC documentation for Array
24+
*/
25+
module.exports.getDoc = function(name, env) {
26+
if (!env) env = Object.keys(docs);
27+
28+
for (var i = 0; i < env.length; i++) {
29+
var d = docs[env[i]][name];
30+
if (d) return d;
31+
}
32+
};

test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ var test = require('tape'),
22
g = require('./');
33

44
test('globals-docs', function(t) {
5-
t.equal(typeof g, 'object');
5+
t.equal(typeof g.docs, 'object');
6+
7+
t.equal(g.getDoc('Array'), 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array', 'Array');
8+
t.equal(g.getDoc('Buffer'), 'https://nodejs.org/api/buffer.html', 'Buffer');
9+
610
t.end();
711
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy