Socket
Socket
Sign inDemoInstall

babel-plugin-transform-es2015-spread

Package Overview
Dependencies
3
Maintainers
6
Versions
35
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-transform-es2015-spread

Compile ES2015 spread to ES5


Version published
Maintainers
6
Install size
2.24 MB
Created

Package description

What is babel-plugin-transform-es2015-spread?

The babel-plugin-transform-es2015-spread npm package is used to compile ES2015 spread syntax to a version of JavaScript that can run in environments that do not support this syntax natively. Spread syntax allows an iterable such as an array to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected, or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected.

What are babel-plugin-transform-es2015-spread's main functionalities?

Function Calls

This feature allows an array of arguments to be spread out and passed as individual arguments to a function call. The code sample demonstrates spreading an array into a function call.

function sum(x, y, z) { return x + y + z; } const numbers = [1, 2, 3]; console.log(sum(...numbers));

Array Literals

Spread syntax can be used to concatenate arrays or insert multiple elements into an array at once. The code sample shows how to use spread syntax to merge arrays.

const parts = ['shoulders', 'knees']; const body = ['head', ...parts, 'toes'];

Object Literals

This feature allows for the properties of one or more source objects to be copied into a new object. The code sample demonstrates both cloning and merging objects using spread syntax.

const obj1 = { foo: 'bar', x: 42 }; const obj2 = { foo: 'baz', y: 13 }; const clonedObj = { ...obj1 }; const mergedObj = { ...obj1, ...obj2 };

Other packages similar to babel-plugin-transform-es2015-spread

Readme

Source

babel-plugin-transform-es2015-spread

Compile ES2015 spread to ES5

Installation

npm install --save-dev babel-plugin-transform-es2015-spread

Usage

.babelrc

// without options
{
  "plugins": ["transform-es2015-spread"]
}

// with options
{
  "plugins": [
    ["transform-es2015-spread", {
      "loose": true
    }]
  ]
}

Via CLI

babel --plugins transform-es2015-spread script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["transform-es2015-spread"]
});

Options

  • loose - All iterables are assumed to be arrays.

Keywords

FAQs

Last updated on 20 Jan 2017

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc