
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
babel-plugin-transform-es2015-parameters
Advanced tools
Compile ES2015 default and rest parameters to ES5
The babel-plugin-transform-es2015-parameters package is a Babel plugin that transforms ES2015 (ES6) parameter features to ES5. This includes default parameters, rest parameters, and destructuring in function parameters.
Default Parameters
This feature allows you to set default values for function parameters. If no argument is provided for the parameter, the default value is used.
function greet(name = 'World') { console.log('Hello ' + name); } greet(); // Hello World greet('Alice'); // Hello Alice
Rest Parameters
Rest parameters allow you to represent an indefinite number of arguments as an array. This is useful for functions that need to handle a variable number of arguments.
function sum(...numbers) { return numbers.reduce((acc, num) => acc + num, 0); } console.log(sum(1, 2, 3)); // 6
Destructuring in Parameters
Destructuring in function parameters allows you to unpack values from objects or arrays directly in the parameter list. This can make your code more readable and concise.
function printCoordinates({ x, y }) { console.log(`X: ${x}, Y: ${y}`); } printCoordinates({ x: 10, y: 20 }); // X: 10, Y: 20
This package transforms ES2015 destructuring syntax to ES5. It focuses specifically on destructuring assignments and function parameters, similar to the destructuring feature in babel-plugin-transform-es2015-parameters.
This package transforms ES2015 spread syntax to ES5. While it focuses on spread operations, it complements the rest parameters feature of babel-plugin-transform-es2015-parameters by handling array and object spread.
This package ensures that function names are correctly assigned in ES2015. It is not directly related to parameters but is often used alongside parameter transformation plugins to ensure function names are preserved.
Compile ES2015 default and rest parameters to ES5
This plugin transforms ES2015 parameters to ES5, this includes:
npm install --save-dev babel-plugin-transform-es2015-parameters
Default parameters desugar into let
declarations to retain proper semantics. If this is
not supported in your environment then you'll need the
transform-block-scoping plugin.
.babelrc
(Recommended).babelrc
{
"plugins": ["transform-es2015-parameters"]
}
babel --plugins transform-es2015-parameters script.js
require("babel-core").transform("code", {
plugins: ["transform-es2015-parameters"]
});
FAQs
Compile ES2015 default and rest parameters to ES5
The npm package babel-plugin-transform-es2015-parameters receives a total of 1,119,988 weekly downloads. As such, babel-plugin-transform-es2015-parameters popularity was classified as popular.
We found that babel-plugin-transform-es2015-parameters demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 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.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.