# es6-arrow-function

> Shorthand arrow functions compiled to ES5.

Latest version **0.6.6** (published 2014-12-31) · Apache 2 license · 0 weekly downloads

## Install

```sh
npm install es6-arrow-function
pnpm add es6-arrow-function
yarn add es6-arrow-function
bun add es6-arrow-function
```

Provides the command `es6-arrow-function`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.6 |
| Published | 2014-12-31 |
| First published | 2013-11-19 |
| Weekly downloads | 0 |
| License | Apache 2 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 52 |
| Author | Square, Inc. |
| Maintainers | eventualbuddha, square |

## Links

- npm: https://www.npmjs.com/package/es6-arrow-function
- Repository: git@github.com:square/es6-arrow-function
- Homepage: https://github.com/square/es6-arrow-function
- Issues: https://github.com/square/es6-arrow-function/issues
- npm.io page: https://npm.io/package/es6-arrow-function

## Dependencies (3)

- [recast](https://npm.io/package/recast.md) ^0.9.11
- [through](https://npm.io/package/through.md) ~2.3.6
- [ast-util](https://npm.io/package/ast-util.md) ^0.6.0

## Recent versions

- 0.6.6 (latest) — 2014-12-31
- 0.6.5 — 2014-12-19
- 0.6.4 — 2014-12-18
- 0.6.3 — 2014-12-14
- 0.6.2 — 2014-10-29
- 0.6.1 — 2014-10-27
- 0.6.0 — 2014-10-26
- 0.5.1 — 2014-09-25
- 0.5.0 — 2014-09-03
- 0.4.0 — 2014-09-03
- 0.3.1 — 2014-05-02
- 0.3.0 — 2014-04-11
- 0.2.0 — 2014-04-01
- 0.1.1 — 2013-11-20
- 0.1.0 — 2013-11-19
- … 1 more at https://npm.io/package/es6-arrow-function/versions

## README

# es6-arrow-function [![Build Status](https://travis-ci.org/esnext/es6-arrow-function.svg?branch=master)](https://travis-ci.org/esnext/es6-arrow-function)

Compiles JavaScript written using arrow functions to use ES5-compatible
function syntax. For example, this:

```js
[1, 2, 3].map(n => n * 2);
```

compiles to this:

```js
[1, 2, 3].map(function(n) { return n * 2; });
```

For more information about the proposed syntax, see the [TC39 wiki page on
arrow functions](http://tc39wiki.calculist.org/es6/arrow-functions/).

## Install

```
$ npm install es6-arrow-function
```

## Usage

```js
$ node
> var compile = require('es6-arrow-function').compile;
[Function]
```

Without arguments:

```js
> compile('$(() => main());').code;
'$(function() { return main(); });'
```

With a single argument:

```js
> compile('[1, 2, 3].map(n => n * 2);').code;
'[1, 2, 3].map(function(n) { return n * 2; });'
```

With multiple arguments:

```js
> compile('[1, 2, 3].map((n, i) => n * i);').code;
'[1, 2, 3].map(function(n, i) { return n * i; });'
```

It binds the current context:

```js
> compile('stream.on("data", d => this.data += d);').code;
'stream.on("data", (function(d) { return this.data += d; }).bind(this));'
```

Or work directly with the AST:

```js
$ cat ast.json
{
  "type": "Program",
  "body": [
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "CallExpression",
        "callee": {
          "type": "Identifier",
          "name": "$"
        },
        "arguments": [
          {
            "type": "ArrowFunctionExpression",
            "id": null,
            "params": [],
            "defaults": [],
            "body": {
              "type": "CallExpression",
              "callee": {
                "type": "Identifier",
                "name": "main"
              },
              "arguments": []
            },
            "rest": null,
            "generator": false,
            "expression": true
          }
        ]
      }
    }
  ]
}
$ node
> var transform = require('es6-arrow-function').transform;
[Function]
> console.log(JSON.stringify(transform(require('./ast.json')), null, 2));
{
  "type": "Program",
  "body": [
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "CallExpression",
        "callee": {
          "type": "Identifier",
          "name": "$"
        },
        "arguments": [
          {
            "type": "FunctionExpression",
            "id": null,
            "params": [],
            "defaults": [],
            "body": {
              "type": "BlockStatement",
              "body": [
                {
                  "type": "ReturnStatement",
                  "argument": {
                    "type": "CallExpression",
                    "callee": {
                      "type": "Identifier",
                      "name": "main"
                    },
                    "arguments": []
                  }
                }
              ]
            },
            "rest": null,
            "generator": false,
            "expression": false
          }
        ]
      }
    }
  ]
}
```

## Command line

If installing via `npm` a command line tool will be available called `es6-arrow-function`.

```
$ echo "()=>123" | es6-arrow-function
(function () {
  return 123;
});
```

```
$ es6-arrow-function $file
(function () {
  return 123;
});
```

## Browserify

Browserify support is built in.

```
$ npm install es6-arrow-function  # install local dependency
$ browserify -t es6-arrow-function $file
// BOILERPLATE
(function () {
  return 123;
});
```

## Contributing

[![Build Status](https://travis-ci.org/square/es6-arrow-function.png?branch=master)](https://travis-ci.org/square/es6-arrow-function)

### Setup

First, install the development dependencies:

```
$ npm install
```

Then, try running the tests:

```
$ npm test
```

### Pull Requests

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

Any contributors to the master es6-arrow-function repository must sign the
[Individual Contributor License Agreement (CLA)][cla].  It's a short form that
covers our bases and makes sure you're eligible to contribute.

[cla]: https://spreadsheets.google.com/spreadsheet/viewform?formkey=dDViT2xzUHAwRkI3X3k5Z0lQM091OGc6MQ&ndplr=1

When you have a change you'd like to see in the master repository, [send a pull
request](https://github.com/square/es6-arrow-function/pulls). Before we merge
your request, we'll make sure you're in the list of people who have signed a
CLA.

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