Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cdlewis/idx-to-optional-chaining
JSCodeShift codemod that transforms usage of idx to the draft optional chaining standard.
https://github.com/cdlewis/idx-to-optional-chaining
codemod flow idx javascript jscodeshift optional-chaining typescript
Last synced: about 1 month ago
JSON representation
JSCodeShift codemod that transforms usage of idx to the draft optional chaining standard.
- Host: GitHub
- URL: https://github.com/cdlewis/idx-to-optional-chaining
- Owner: cdlewis
- Created: 2019-01-20T10:52:50.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T10:15:19.000Z (about 2 years ago)
- Last Synced: 2024-09-18T03:36:14.495Z (5 months ago)
- Topics: codemod, flow, idx, javascript, jscodeshift, optional-chaining, typescript
- Language: JavaScript
- Homepage:
- Size: 959 KB
- Stars: 19
- Watchers: 3
- Forks: 3
- Open Issues: 11
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
- awesome-codemods - idx-to-optional-chaining - JSCodeShift codemod that transforms usage of idx to the draft optional chaining standard. (ESNext)
README
# idx to optional chaining [![Build Status](https://travis-ci.com/cdlewis/idx-to-optional-chaining.svg?branch=master)](https://travis-ci.com/cdlewis/idx-to-optional-chaining)
Facebook's [idx](https://github.com/facebookincubator/idx) was a useful helper prior to the [optional chaining](https://github.com/tc39/proposal-optional-chaining) maturing as a standard because it
played nicely with Flow. But now optional chaining is stage 4 and has Flow/Typescript support. This codemod
will convert transform most usages of idx.## Usage
```console
foo@bar:~$ git clone [email protected]:cdlewis/idx-to-optional-chaining.git
foo@bar:~$ npm install -g jscodeshift
foo@bar:~$ jscodeshift -t idx-to-optional-chaining/index.js file-to-transform.js
```## Example
Before:
```js
import idx from "idx";let a = idx(a, _ => _.b);
let b = idx(a, _ => _.b.c);
let c = idx(a, _ => _.b.c.d);
let d = idx(a, _ => _[0][1][2]);
let e = idx(a, _ => _.b[0].c[variable]);
```After:
```js
let a = a?.b
let b = a?.b?.c
let c = a?.b?.c?.d
let d = a?.0?.[1]?.[2]
let e = a?.b?.[0]?.c?.[variable]
```