Debian Codegraph @

codemods/babel-plugin-codemod-object-assign-to-object-spread/README.md

raw
1 # @babel/plugin-codemod-object-assign-to-object-spread
2
3 Transforms old code that uses `Object.assign` with an Object Literal as
4 the first param to use Object Spread syntax.
5
6 ## Examples
7
8 ```js
9 const obj = Object.assign({
10 test1: 1,
11 }, other, {
12 test2: 2,
13 }, other2);
14 ```
15
16 Is transformed to:
17
18 ```js
19 const obj = {
20 test1: 1,
21 ...other,
22 test2: 2,
23 ...other2,
24 };
25 ```
26
27 ## Installation
28
29 ```sh
30 npm install --save-dev @babel/plugin-codemod-object-assign-to-object-spread
31 ```
32
33 ## Usage
34
35 ### Via `.babelrc` (Recommended)
36
37 **.babelrc**
38
39 ```jsonc
40 {
41 "plugins": ["@babel/plugin-codemod-object-assign-to-object-spread"]
42 }
43 ```
44
45 ### Via CLI
46
47 ```sh
48 babel --plugins @babel/plugin-codemod-object-assign-to-object-spread script.js
49 ```
50
51 ### Via Node API
52
53 ```javascript
54 require("@babel/core").transform("code", {
55 plugins: ["@babel/plugin-codemod-object-assign-to-object-spread"]
56 });
57 ```