npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

es6-arrow-function

v0.6.6

Published

Shorthand arrow functions compiled to ES5.

Downloads

554

Readme

es6-arrow-function Build Status

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

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

compiles to this:

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

For more information about the proposed syntax, see the TC39 wiki page on arrow functions.

Install

$ npm install es6-arrow-function

Usage

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

Without arguments:

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

With a single argument:

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

With multiple arguments:

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

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

$ 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

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). It's a short form that covers our bases and makes sure you're eligible to contribute.

When you have a change you'd like to see in the master repository, send a pull request. Before we merge your request, we'll make sure you're in the list of people who have signed a CLA.