Generate JavaScript documentation as a list of parsed JSDoc comments, given a root file as a path.
Parameters
indexes
(Array<string> | string) files to processoptions
Object optionsoptions.external
Array<string> a string regex / glob match pattern that defines what external modules will be whitelisted and included in the generated documentation.options.polyglot
[boolean] parse comments with a regex rather than a proper parser. This enables support of non-JavaScript languages but reduces documentation's ability to infer structure of code. (optional, defaultfalse
)options.shallow
[boolean] whether to avoid dependency parsing even in JavaScript code. With the polyglot option set, this has no effect. (optional, defaultfalse
)options.order
[Array<(string | Object)>] optional array that defines sorting order of documentation (optional, default[]
)options.access
[Array<string>] an array of access levels to output in documentation (optional, default[]
)options.hljs
[Object] hljs optional optionsoptions.inferPrivate
[string] a valid regular expression string to infer whether a code element should be private, given its naming structure. For instance, you can specifyinferPrivate: '^_'
to automatically treat methods named like_myMethod
as private.options.extension
[(string | Array<string>)] treat additional file extensions as JavaScript, extending the default set ofjs
,es6
, andjsx
.
callback
Function to be called when the documentation generation is complete, with (err, result) argumentsj
Examples
var documentation = require('documentation');
documentation.build(['index.js'], {
// only output comments with an explicit @public tag
access: ['public']
}, function (err, 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 undefined calls callback
Generate JavaScript documentation given a list of inputs. This internal method does not support require-following and it returns its results synchronously, rather than by calling a callback.
Parameters
indexes
Array<string> files to processoptions
Object optionsoptions.external
Array<string> a string regex / glob match pattern that defines what external modules will be whitelisted and included in the generated documentation.options.polyglot
[boolean] parse comments with a regex rather than a proper parser. This enables support of non-JavaScript languages but reduces documentation's ability to infer structure of code. (optional, defaultfalse
)options.shallow
[boolean] whether to avoid dependency parsing even in JavaScript code. With the polyglot option set, this has no effect. (optional, defaultfalse
)options.order
[Array<(string | Object)>] optional array that defines sorting order of documentation (optional, default[]
)options.access
[Array<string>] an array of access levels to output in documentation (optional, default[]
)options.hljs
[Object] hljs optional optionsoptions.inferPrivate
[string] a valid regular expression string to infer whether a code element should be private, given its naming structure. For instance, you can specifyinferPrivate: '^_'
to automatically treat methods named like_myMethod
as private.options.extension
[(string | Array<string>)] treat additional file extensions as JavaScript, extending the default set ofjs
,es6
, andjsx
.
Examples
var documentation = require('documentation');
var results = documentation.buildSync(['index.js']);
// results 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 Object list of results
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<string> | string) files to processoptions
Object optionsoptions.external
Array<string> a string regex / glob match pattern that defines what external modules will be whitelisted and included in the generated documentation.options.polyglot
[boolean] parse comments with a regex rather than a proper parser. This enables support of non-JavaScript languages but reduces documentation's ability to infer structure of code. (optional, defaultfalse
)options.shallow
[boolean] whether to avoid dependency parsing even in JavaScript code. With the polyglot option set, this has no effect. (optional, defaultfalse
)options.inferPrivate
[string] a valid regular expression string to infer whether a code element should be private, given its naming structure. For instance, you can specifyinferPrivate: '^_'
to automatically treat methods named like_myMethod
as private.options.extension
[(string | Array<string>)] treat additional file extensions as JavaScript, extending the default set ofjs
,es6
, andjsx
.
callback
Function to be called when the documentation generation is complete, with (err, result) arguments
Examples
documentation.lint('file.js', {}, function (err, lintOutput) {
if (err) {
throw err;
}
if (lintOutput) {
console.log(lintOutput);
process.exit(1);
} else {
process.exit(0);
}
});
Returns undefined calls callback
Documentation's formats are modular methods that take comments and options as input and call a callback with writable objects, like stringified JSON, markdown strings, or Vinyl objects for HTML output.
Formats documentation as HTML.
Parameters
comments
Array<Object> parsed commentsoptions
Object Options that can customize the outputoptions.theme
[string] Name of a module used for an HTML theme. (optional, default'default_theme'
)
callback
Function Called with array of results as vinyl-fs objects.
Examples
var documentation = require('documentation');
var streamArray = require('stream-array');
var vfs = require('vinyl-fs');
documentation.build(['index.js'], {}, function (err, res) {
documentation.formats.html(res, {}, function(output) {
streamArray(output).pipe(vfs.dest('./output-directory'));
});
});
Returns undefined Calls callback.
Formats documentation as Markdown.
Parameters
comments
Array<Object> parsed commentsoptions
Object Options that can customize the outputcallback
Function called with null, string
Examples
var documentation = require('documentation');
var fs = require('fs');
documentation.build(['index.js'], {}, function (err, res) {
documentation.formats.md(res, {}, function(output) {
// output is a string of JSON data
fs.writeFileSync('./output.md', output);
});
});
Returns undefined calls callback
Formats documentation as a JSON string.
Parameters
comments
Array<Object> parsed commentsopts
Object Options that can customize the outputcallback
Function called with null, string
Examples
var documentation = require('documentation');
var fs = require('fs');
documentation.build(['index.js'], {}, function (err, res) {
documentation.formats.json(res, {}, function(output) {
// output is a string of JSON data
fs.writeFileSync('./output.json', output);
});
});
Returns undefined calls callback