Skip to content

Extracts all the functions from a Javascript file into an array of objects.

Notifications You must be signed in to change notification settings

andydion/function-extractor

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Provides an array of objects listing the names and types of functions found in a Javascript file.

Based on fn-extractor, except this one works with the latest Esprima, catches more corner cases, reports errors, and covers Coffeescript.

Used by Panino and Biscotto to report doc coverage.

Installation

npm install function-extractor

Usage

You can use this module in two ways. If you don't already have an Esprima AST of your code, do this:

var fs = require("fs");
var functionExtractor = require("function-extractor");

var source = fs.readFileSync("./sample.js", "utf8")

var functions = functionExtractor.parse(source);

where source is the text read from your Javascript file. You can also pass {coffeescript: true} if your source file is a Coffeescript file.

Otherwise, if you've already parsed the file, do this:

var functionExtractor = require("function-extractor");

var functions = functionExtractor.interpret(ast);

where ast is the Esprima.parse() result. Note that you must pass the range and loc options to Esprima.

About

Extracts all the functions from a Javascript file into an array of objects.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 71.5%
  • CoffeeScript 28.5%