function-comment
Given some JavaScript and the line on which a function is defined it returns comments and jsdocs found right above that function.
Last updated 7 years ago by thlorenz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install function-comment 
SYNC missed versions from official npm registry.

function-comment build status

testling badge

Given some JavaScript and the line on which a function is defined it returns comments and jsdocs found right above that function.

var findex = require('findex');
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 comment = findex(src, lineno);
  console.log(comment);
});

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
 */

Installation

npm install function-comment

API

findex (src, lineno)

/**
 * Finds any concecutive 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 {String} comment or empty if none was found
 */

License

MIT

Current Tags

  • 0.2.2                                ...           latest (7 years ago)

5 Versions

  • 0.2.2                                ...           7 years ago
  • 0.2.1                                ...           7 years ago
  • 0.2.0                                ...           7 years ago
  • 0.1.1                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (5)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |