File tree Expand file tree Collapse file tree 3 files changed +73
-2
lines changed Expand file tree Collapse file tree 3 files changed +73
-2
lines changed Original file line number Diff line number Diff line change 1
1
# globals-docs
2
2
3
3
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
Original file line number Diff line number Diff line change 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
+ } ;
Original file line number Diff line number Diff line change @@ -2,6 +2,10 @@ var test = require('tape'),
2
2
g = require ( './' ) ;
3
3
4
4
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
+
6
10
t . end ( ) ;
7
11
} ) ;
You can’t perform that action at this time.
0 commit comments