Skip to content

Commit 596c23a

Browse files
committed
Test examples, add API docs. Fixes #2
1 parent 672ac97 commit 596c23a

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

README.md

+40
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,43 @@
55

66
Utilities that help in the process of building theme modules
77
for documentation.js.
8+
9+
## API
10+
11+
### link
12+
13+
Helper used to automatically link items to global JS documentation or to internal
14+
documentation.
15+
16+
**Parameters**
17+
18+
- `text` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** text to potentially link
19+
- `getHref` **\[[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)]** a function that tries
20+
to find a URL to point a named link to
21+
- `description`
22+
23+
**Examples**
24+
25+
```javascript
26+
link('string').url // => 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String'
27+
```
28+
29+
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** [mdast](https://www.npmjs.com/package/mdast) node
30+
31+
### formatType
32+
33+
Helper used to format JSDoc-style type definitions into HTML or Markdown.
34+
35+
**Parameters**
36+
37+
- `node` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** type object in doctrine style
38+
- `getHref` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a function that tries
39+
to find a URL to point a named link to
40+
41+
**Examples**
42+
43+
```javascript
44+
formatType({ type: 'NameExpression', name: 'String' })[0].url // => 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String'
45+
```
46+
47+
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>** array of [mdast](https://www.npmjs.com/package/mdast) syntax trees

index.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ function t(text) {
1414
* @param {function} [getHref] - a function that tries
1515
* to find a URL to point a named link to
1616
* @returns {Object} [mdast](https://www.npmjs.com/package/mdast) node
17+
* @example
18+
* link('string').url // => 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String'
1719
*/
1820
function link(text, getHref, description) {
1921
var href = (getHref && getHref(text)) || globalsDocs.getDoc(text);
@@ -59,10 +61,7 @@ function decorate(formatted, str, prefix) {
5961
* to find a URL to point a named link to
6062
* @returns {Object[]} array of [mdast](https://www.npmjs.com/package/mdast) syntax trees
6163
* @example
62-
* var x = { type: 'NameExpression', name: 'String' };
63-
* // in template
64-
* // {{ type x }}
65-
* // generates String
64+
* formatType({ type: 'NameExpression', name: 'String' })[0].url // => 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String'
6665
*/
6766
function formatType(node, getHref) {
6867
var result = [];

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"description": "helpers for building themes with documentation.js",
55
"main": "index.js",
66
"scripts": {
7-
"test": "tap --coverage test"
7+
"test": "tap --coverage test && npm run jsdoctest",
8+
"jsdoctest": "mocha --require jsdoctest index.js",
9+
"doc": "documentation readme index.js --section=API"
810
},
911
"keywords": [
1012
"documentation",
@@ -20,6 +22,9 @@
2022
"unist-builder": "^1.0.0"
2123
},
2224
"devDependencies": {
25+
"documentation": "4.0.0-beta4",
26+
"jsdoctest": "1.6.0",
27+
"mocha": "2.5.3",
2328
"remark": "^4.1.2",
2429
"tap": "^5.7.0"
2530
}

0 commit comments

Comments
 (0)