|
1 | 1 | const dox = require('dox');
|
2 | 2 |
|
| 3 | +/** |
| 4 | + * Format string as name. |
| 5 | + * |
| 6 | + * @example formatStringForName('module.exports.parser'); |
| 7 | + * @param {String} contents String to format. |
| 8 | + * @return {String} Formatted string. |
| 9 | + * @private |
| 10 | + */ |
| 11 | + |
3 | 12 | const formatStringForName = content =>
|
4 | 13 | content.toString()
|
5 | 14 | .replace(/module\.exports\.|\.prototype|\(\)/g, '');
|
6 | 15 |
|
| 16 | +/** |
| 17 | + * Format string as param. |
| 18 | + * |
| 19 | + * @example formatStringForParam('[optional param]'); |
| 20 | + * @param {String} contents String to format. |
| 21 | + * @return {String} Formatted string. |
| 22 | + * @private |
| 23 | + */ |
| 24 | + |
7 | 25 | const formatStringForParam = content =>
|
8 | 26 | content.toString()
|
9 | 27 | .replace(/\[|\]/g, '');
|
10 | 28 |
|
| 29 | +/** |
| 30 | + * Format string as UID. |
| 31 | + * |
| 32 | + * @example formatStringForUID('example string'); |
| 33 | + * @param {String} contents String to format. |
| 34 | + * @return {String} Formatted string. |
| 35 | + * @private |
| 36 | + */ |
| 37 | + |
11 | 38 | const formatStringForUID = content =>
|
12 | 39 | content.toString()
|
13 | 40 | .toLowerCase()
|
14 | 41 | .replace(/[^\w\.]+/g, '-')
|
15 | 42 | .replace(/^-|-$/g, '');
|
16 | 43 |
|
| 44 | +/** |
| 45 | + * dox parser for doxdox. |
| 46 | + * |
| 47 | + * @example parser(content, 'index.js').then(methods => console.log(methods)); |
| 48 | + * @param {String} content Contents of file. |
| 49 | + * @param {String} filename Name of file. Used to generate UIDs. |
| 50 | + * @return {Promise} Promise with methods parsed from contents. |
| 51 | + * @public |
| 52 | + */ |
| 53 | + |
17 | 54 | const parser = (content, filename) =>
|
18 | 55 | dox.parseComments(content, {'raw': true}).filter(method => !method.ignore && method.ctx)
|
19 | 56 | .map(method => ({
|
|
0 commit comments