# function-extractor

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

Latest version **0.0.5** (published 2013-01-29) · 0 weekly downloads

## Install

```sh
npm install function-extractor
pnpm add function-extractor
yarn add function-extractor
bun add function-extractor
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2013-01-29 |
| First published | 2012-11-05 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.6.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | gjtorikian |

## Links

- npm: https://www.npmjs.com/package/function-extractor
- Repository: https://github.com/gjtorikian/function-extractor
- npm.io page: https://npm.io/package/function-extractor

## Dependencies (2)

- [esprima](https://npm.io/package/esprima.md)
- [coffee-script-redux](https://npm.io/package/coffee-script-redux.md)

## Recent versions

- 0.0.5 (latest) — 2013-01-29
- 0.0.4 — 2012-11-14
- 0.0.2 — 2012-11-06
- 0.0.1 — 2012-11-05

## README

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

Based on [fn-extractor](https://github.com/goatslacker/fn-extractor), except this one works with the latest Esprima, catches more corner cases, reports errors, and covers Coffeescript.

Used by [Panino](https://github.com/c9/panino-docs) and [Biscotto](https://github.com/gjtorikian/biscotto) to report doc coverage.

# Installation

```bash
npm install function-extractor
```

# Usage

You can use this module in two ways. If you don't already have an [Esprima](https://github.com/ariya/esprima) AST of your code, do this:

```javascript
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:

```javascript
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.

---
_Source: https://npm.io/package/function-extractor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
