documentation/docs/NODE_API.md
Tom MacWright ab494dd1b3
feat: use reference links for Markdown output, improving brevity
* Use reference links in Markdown.

Fixes https://github.com/documentationjs/documentation/issues/948.

This approach might be problematic when inserting markdown under a readme heading if the readme already has link references with conflicting ID’s.

* Reference links edits:

- fix broken normalize() utility in test suite so that it produces
  output that doesn't choke referenceLinks.
- add DocumentationConfig option `--noReferenceLinks` which will be
  **internal only**, and turns off reference links for `readme` mode
- rebuilds test output with these changes

unrelated but minor

- includes .prettierrc and updates calls to prettier to use that instead
  of CLI options

* chore: update test snapshots

* Update readme snap
2018-03-01 15:18:20 -08:00

202 lines
6.1 KiB
Markdown

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
### Table of Contents
- [lint][1]
- [build][2]
- [formats][3]
- [formats.html][4]
- [formats.markdown][5]
- [formats.json][6]
## lint
Lint files for non-standard or incorrect documentation
information, returning a potentially-empty string
of lint information intended for human-readable output.
**Parameters**
- `indexes` **([Array][7]&lt;[string][8]> | [string][8])** files to process
- `args` **[Object][9]** args
- `args.external` **[Array][7]&lt;[string][8]>** a string regex / glob match pattern
that defines what external modules will be whitelisted and included in the
generated documentation.
- `args.shallow` **[boolean][10]** whether to avoid dependency parsing
even in JavaScript code. (optional, default `false`)
- `args.inferPrivate` **[string][8]?** a valid regular expression string
to infer whether a code element should be private, given its naming structure.
For instance, you can specify `inferPrivate: '^_'` to automatically treat
methods named like `_myMethod` as private.
- `args.extension` **([string][8] \| [Array][7]&lt;[string][8]>)?** treat additional file extensions
as JavaScript, extending the default set of `js`, `es6`, and `jsx`.
**Examples**
```javascript
documentation.lint('file.js').then(lintOutput => {
if (lintOutput) {
console.log(lintOutput);
process.exit(1);
} else {
process.exit(0);
}
});
```
Returns **[Promise][11]** promise with lint results
## build
Generate JavaScript documentation as a list of parsed JSDoc
comments, given a root file as a path.
**Parameters**
- `indexes` **([Array][7]&lt;[string][8]> | [string][8])** files to process
- `args` **[Object][9]** args
- `args.external` **[Array][7]&lt;[string][8]>** a string regex / glob match pattern
that defines what external modules will be whitelisted and included in the
generated documentation.
- `args.shallow` **[boolean][10]** whether to avoid dependency parsing
even in JavaScript code. (optional, default `false`)
- `args.order` **[Array][7]&lt;([string][8] \| [Object][9])>** optional array that
defines sorting order of documentation (optional, default `[]`)
- `args.access` **[Array][7]&lt;[string][8]>** an array of access levels
to output in documentation (optional, default `[]`)
- `args.hljs` **[Object][9]?** hljs optional args
- `args.hljs.highlightAuto` **[boolean][10]** hljs automatically detect language (optional, default `false`)
- `args.hljs.languages` **[Array][7]?** languages for hljs to choose from
- `args.inferPrivate` **[string][8]?** a valid regular expression string
to infer whether a code element should be private, given its naming structure.
For instance, you can specify `inferPrivate: '^_'` to automatically treat
methods named like `_myMethod` as private.
- `args.extension` **([string][8] \| [Array][7]&lt;[string][8]>)?** treat additional file extensions
as JavaScript, extending the default set of `js`, `es6`, and `jsx`.
**Examples**
```javascript
var documentation = require('documentation');
documentation.build(['index.js'], {
// only output comments with an explicit @public tag
access: ['public']
}).then(res => {
// res is an array of parsed comments with inferred properties
// and more: everything you need to build documentation or
// any other kind of code data.
});
```
Returns **[Promise][11]** results
## formats
Documentation's formats are modular methods that take comments
and config as input and return Promises with results,
like stringified JSON, markdown strings, or Vinyl objects for HTML
output.
## formats.html
Formats documentation as HTML.
**Parameters**
- `comments` **[Array][7]&lt;[Comment][12]>** parsed comments
- `config` **[Object][9]** Options that can customize the output
- `config.theme` **[string][8]** Name of a module used for an HTML theme. (optional, default `'default_theme'`)
**Examples**
```javascript
var documentation = require('documentation');
var streamArray = require('stream-array');
var vfs = require('vinyl-fs');
documentation.build(['index.js'])
.then(documentation.formats.html)
.then(output => {
streamArray(output).pipe(vfs.dest('./output-directory'));
});
```
Returns **[Promise][11]&lt;[Array][7]&lt;[Object][9]>>** Promise with results
## formats.markdown
Formats documentation as
[Markdown][13].
**Parameters**
- `comments` **[Array][7]&lt;[Object][9]>** parsed comments
- `args` **[Object][9]** Options that can customize the output
**Examples**
```javascript
var documentation = require('documentation');
var fs = require('fs');
documentation.build(['index.js'])
.then(documentation.formats.md)
.then(output => {
// output is a string of Markdown data
fs.writeFileSync('./output.md', output);
});
```
Returns **[Promise][11]&lt;[string][8]>** a promise of the eventual value
## formats.json
Formats documentation as a JSON string.
**Parameters**
- `comments` **[Array][7]&lt;[Comment][12]>** parsed comments
**Examples**
```javascript
var documentation = require('documentation');
var fs = require('fs');
documentation.build(['index.js'])
.then(documentation.formats.json)
.then(output => {
// output is a string of JSON data
fs.writeFileSync('./output.json', output);
});
```
Returns **[Promise][11]&lt;[string][8]>**
[1]: #lint
[2]: #build
[3]: #formats
[4]: #formatshtml
[5]: #formatsmarkdown
[6]: #formatsjson
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
[12]: https://developer.mozilla.org/docs/Web/API/Comment/Comment
[13]: http://daringfireball.net/projects/markdown/