Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
es6-arrow-function
Advanced tools
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.
$ npm install es6-arrow-function
$ 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
}
]
}
}
]
}
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 support is built in.
$ npm install es6-arrow-function # install local dependency
$ browserify -t es6-arrow-function $file
// BOILERPLATE
(function () {
return 123;
});
First, install the development dependencies:
$ npm install
Then, try running the tests:
$ npm test
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)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.
FAQs
Shorthand arrow functions compiled to ES5.
The npm package es6-arrow-function receives a total of 33 weekly downloads. As such, es6-arrow-function popularity was classified as not popular.
We found that es6-arrow-function demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.