const Comments = require('{%= name %}');
const comments = new Comments();
const ast = comments.parse(str);
console.log(ast);
Parses a comment like this:
/**
* Create an instance of `CustomClass` with the given `options`.
*
* @param {String} options
* @api public
*/
class CustomClass {
constructor(options) {
this.options = options;
}
set(type, fn) {
// do stuff
}
}
Into an array of comment objects, like this:
[
{
type: 'BlockComment',
value: '\nCreate an instance of `CustomClass` with the given `options`.\n\n@param {String} options\n@api public',
range: [0, 117],
loc: { start: { line: 1, column: 0 }, end: { line: 6, column: 3 } },
codeStart: 119,
raw:
'*\n * Create an instance of `CustomClass` with the given `options`.\n *\n * @param {String} options\n * @api public\n ',
code: {
context: {
type: 'class',
ctor: 'CustomClass',
name: 'CustomClass',
extends: undefined,
string: 'new CustomClass()'
},
value: 'class CustomClass {',
range: [119, 138],
loc: { start: { line: 8, column: 0 }, end: { line: 8, column: 19 } }
},
description: 'Create an instance of `CustomClass` with the given `options`.',
footer: '',
examples: [],
tags: [
{
title: 'param',
name: 'options',
description: '',
type: { type: 'NameExpression', name: 'String' }
},
{ title: 'api', name: 'public', description: '' }
],
inlineTags: []
}
]
{%= apidocs("index.js") %}