https://github.com/alwarg/obj-destructure-codemod
https://github.com/alwarg/obj-destructure-codemod
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/alwarg/obj-destructure-codemod
- Owner: AlwarG
- License: mit
- Created: 2020-04-29T09:23:49.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T04:34:49.000Z (over 3 years ago)
- Last Synced: 2025-08-09T05:44:19.388Z (11 months ago)
- Language: JavaScript
- Size: 1.4 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# obj-destructure-codemod
A collection of codemod's for obj-destructure.
## Usage
To run a specific codemod from this project, you would run the following:
```
npx obj-destructure-codemod path/of/files/ or/some**/*glob.js
# or
yarn global add obj-destructure-codemod
obj-destructure-codemod path/of/files/ or/some**/*glob.js
```
# obj-destructure
## Transforms
```
let prop = obj1.prop
let property = obj2.prop;
```
into this
```
let {
prop
} = obj1;
let {
prop: property
} = obj2;
```
# function-arg-obj-destructure
## Transforms
```
function getProp(obj) {
return obj.prop;
}
```
into this
```
function getProp({ prop }) {
return prop;
}
```
**Note:**
```
function printProps(obj) {
console.log(obj.prop1, obj.prop2);
}
```
The above function will not be transformed. Because we have allowable properties length as `1`.
Incase you want to increase this length change [here](https://github.com/AlwarG/obj-destructure-codemod/blob/master/transforms/function-arg-obj-destructure/index.js#L6)
## Contributing
### Installation
* clone the repo
* change into the repo directory
* `yarn`
### Running tests
* `yarn test`
### Update Documentation
* `yarn update-docs`