documentation/docs/NODE_API.md
2022-08-04 02:05:16 +02:00

200 lines
5.7 KiB
Markdown

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
### Table of Contents
* [lint][1]
* [Parameters][2]
* [Examples][3]
* [build][4]
* [Parameters][5]
* [Examples][6]
* [formats][7]
* [formats.markdown][8]
* [Parameters][9]
* [Examples][10]
* [formats.json][11]
* [Parameters][12]
* [Examples][13]
## 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][14]<[string][15]> | [string][15])** files to process
* `args` **[Object][16]** args
* `args.external` **[Array][14]<[string][15]>** a string regex / glob match pattern
that defines what external modules will be whitelisted and included in the
generated documentation.
* `args.shallow` **[boolean][17]** whether to avoid dependency parsing
even in JavaScript code.&#x20;(optional, default `false`)
* `args.inferPrivate` **[string][15]?** 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][15] | [Array][14]<[string][15]>)?** 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][18]** 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][14]<[string][15]> | [string][15])** files to process
* `args` **[Object][16]** args
* `args.external` **[Array][14]<[string][15]>** a string regex / glob match pattern
that defines what external modules will be whitelisted and included in the
generated documentation.
* `args.shallow` **[boolean][17]** whether to avoid dependency parsing
even in JavaScript code.&#x20;(optional, default `false`)
* `args.order` **[Array][14]<([string][15] | [Object][16])>** optional array that
defines sorting order of documentation&#x20;(optional, default `[]`)
* `args.access` **[Array][14]<[string][15]>** an array of access levels
to output in documentation&#x20;(optional, default `[]`)
* `args.hljs` **[Object][16]?** hljs optional args
* `args.hljs.highlightAuto` **[boolean][17]** hljs automatically detect language&#x20;(optional, default `false`)
* `args.hljs.languages` **[Array][14]?** languages for hljs to choose from
* `args.inferPrivate` **[string][15]?** 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][15] | [Array][14]<[string][15]>)?** 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][18]** 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.markdown
Formats documentation as
[Markdown][19].
### Parameters
* `comments` **[Array][14]<[Object][16]>** parsed comments
* `args` **[Object][16]** 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][18]<[string][15]>** a promise of the eventual value
## formats.json
Formats documentation as a JSON string.
### Parameters
* `comments` **[Array][14]<[Comment][20]>** 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][18]<[string][15]>**&#x20;
[1]: #lint
[2]: #parameters
[3]: #examples
[4]: #build
[5]: #parameters-1
[6]: #examples-1
[7]: #formats
[8]: #formatsmarkdown
[9]: #parameters-2
[10]: #examples-2
[11]: #formatsjson
[12]: #parameters-3
[13]: #examples-3
[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[17]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[18]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
[19]: https://daringfireball.net/projects/markdown/
[20]: https://developer.mozilla.org/docs/Web/API/Comment/Comment