Coder Social home page Coder Social logo

timoxley / function-comment Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thlorenz/function-comment

0.0 3.0 0.0 143 KB

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

License: MIT License

function-comment's Introduction

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

Installation

npm install function-comment

API

functionComment (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 {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

function-comment's People

Contributors

thlorenz avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.