Socket
Socket
Sign inDemoInstall

babel-plugin-transform-object-rest-spread

Package Overview
Dependencies
4
Maintainers
5
Versions
39
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-transform-object-rest-spread

Compile object rest and spread to ES5


Version published
Weekly downloads
1.5M
decreased by-16%
Maintainers
5
Install size
2.17 MB
Created
Weekly downloads
 

Package description

What is babel-plugin-transform-object-rest-spread?

The babel-plugin-transform-object-rest-spread package allows developers to use the object rest and spread properties syntax in their JavaScript code. This syntax is part of the ECMAScript 2018 (ES9) specification and enables more concise and readable code when copying properties from one object to another or collecting the remaining properties of an object after certain properties have been extracted.

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

Object Spread

Allows an object's own enumerable properties to be copied into a new object. This is useful for creating a new object with the same properties as an existing object or for combining multiple objects.

{...source}

Object Rest

Enables extracting properties from objects and binding the remaining properties to a new object. This is useful for object destructuring, where you want to separate certain properties from the rest.

{a, b, ...rest}

Other packages similar to babel-plugin-transform-object-rest-spread

Readme

Source

babel-plugin-transform-object-rest-spread

This plugin allows Babel to transform rest properties for object destructuring assignment and spread properties for object literals.

Example

Rest Properties

let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
console.log(x); // 1
console.log(y); // 2
console.log(z); // { a: 3, b: 4 }

Spread Properties

let n = { x, y, ...z };
console.log(n); // { x: 1, y: 2, a: 3, b: 4 }

Installation

npm install --save-dev babel-plugin-transform-object-rest-spread

Usage

.babelrc

{
  "plugins": ["transform-object-rest-spread"]
}

Via CLI

babel --plugins transform-object-rest-spread script.js

Via Node API

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

Options

useBuiltIns

boolean, defaults to false.

By default, this plugin uses Babel's extends helper which polyfills Object.assign. Enabling this option will use Object.assign directly.

.babelrc

{
  "plugins": [
    ["transform-object-rest-spread", { "useBuiltIns": true }]
  ]
}

In

z = { x, ...y };

Out

z = Object.assign({ x }, y);

References

  • Proposal: Object Rest/Spread Properties for ECMAScript
  • Spec

Keywords

FAQs

Last updated on 16 Aug 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