Parses PHPDoc and JSDoc style DocBlocks
npm install parse-docblocks``js
const parseComments = require('parse-docblocks')
const input =
/**
* Summary
*
* Description Line 1
* Description Line 2
*
* Description Line 3
*
* @param string $name Name. Default 'post'.
* @return bool true on success
*/;
const output = parseComments(input, {
prefixPragmas: true, // Should tagName in the output keep the pragma prefix @ or strip it outname
prefixVariables: true, // Should in the output keep the prefix '$' or strip it out
defaultObj: true, // If the @param or @type pragma includes nested values, should those be converted to a default object value
typeToArray: true, // Should types be split on pipes (|) into array values, i.e bool|int => ["bool", "int"]
});
`
`json``
{
"summary": "Summary",
"description": "Description Line 1 Description Line 2\n\nDescription Line 3",
"tags": [
{
"tagName": "@param",
"type": ["string"],
"name": "$name",
"desc": "Name",
"optional": true,
"defaultValue": "post"
},
{
"tagName": "@return",
"type": ["bool"],
"name": null,
"desc": "true on success"
}
]
}