Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

Awesome Lists containing this project

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]
```