- Notifications
You must be signed in to change notification settings - Fork0
eschaefer/codemod-get-to-optional-member-expressions
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This repository contains a codemod script for use withJSCodeshift.
The codemod replaces calls to Lodash'sget method with the nativeoptional chaining proposal for ECMAScript. This is a novel new way to reliably access deeply nested object properties, and can be used now with@babel/plugin-proposal-optional-chaining. It is important to note that this will currently only work withBabel 7. If you are using Babel 6.x, then you will need to update your project to Babel 7 to use this codemod.
constfoo=get(data,'crate.box.present.wrapping.color');constbar=get(data,'crate.box.present.wrapping.color','green');// 👇 Becomes 👇constfoo=data?.crate?.box?.present?.wrapping?.color;constbar=data?.crate?.box?.present?.wrapping?.color||'green';
npm install -g jscodeshiftgit clone https://github.com/eschaefer/codemod-get-to-optional-member-expressions.gitcd codemod-get-to-optional-member-expressions/jscodeshift -t ./lodash-get-to-optional-member-expressions.js<file(s)>
Use the-d option for a dry-run and use-p to print the output forcomparison.
Run tests for this codemod
npm runtest- Add support for
require; - Add support for string literal member expressions
- Add support for array paths
About
Change Lodash `get` functions to ES7 optional member expressions
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published