Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thlorenz/function-comment
Given some JavaScript and the line on which a function is defined it returns comments and jsdocs found right above that function.
https://github.com/thlorenz/function-comment
Last synced: 2 months ago
JSON representation
Given some JavaScript and the line on which a function is defined it returns comments and jsdocs found right above that function.
- Host: GitHub
- URL: https://github.com/thlorenz/function-comment
- Owner: thlorenz
- License: mit
- Created: 2013-07-28T02:44:45.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-07-11T21:26:42.000Z (over 10 years ago)
- Last Synced: 2024-10-18T00:04:18.680Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 245 KB
- Stars: 5
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# function-comment [![build status](https://secure.travis-ci.org/thlorenz/function-comment.png)](http://travis-ci.org/thlorenz/function-comment)
[![testling badge](https://ci.testling.com/thlorenz/function-comment.png)](https://ci.testling.com/thlorenz/function-comment)
Given some JavaScript and the line on which a function is defined it returns comments and jsdocs found right above that function.
```js
var functionComment = require('function-comment');
var fs = require('fs');/**
* Adds c to d and then multiplies the result with d.
*
* @name doingStuff
* @function
* @param c {Number}
* @param d {Number}
* @return {Number} overall result
*/
function doingStuff (c, d) {
return (c + d) * d
}// the function whose comment we are trying to find is on line 13
var lineno = 13;fs.readFile(__filename, 'utf8', function (err, src) {
if (err) return console.error(err);
var res = functionComment(src, lineno);
console.log(res.comment);
console.log('start: ', res.startline);
console.log('end: ', res.endline);
});
```**Output:**
```
/**
* Adds c to d and then multiplies the result with d.
*
* @name doingStuff
* @function
* @param c {Number}
* @param d {Number}
* @return {Number} overall result
*/
start: 5
end: 13
```
## Installationnpm install function-comment
## API
### *functionComment (src, lineno)*
```
/**
* Finds any consecutive comment above the given line of code in the source.
*
* @name exports
* @function
* @param src {String} the JavaScript source
* @param lineno {Number} the number where the function is located (1 based)
* @return {Object} {
* comment : comment string or empty if none was found
* startline : line on which the comment starts or 0 if no comment was found
* endline : line on which the comment ends or 0 if no comment was found
* }
*/
```## License
MIT