babel-plugin-object-path-get-to-optional-chaining
v1.0.0
Published
> This plugin replaces objectPath.get ([object-path](https://github.com/mariocasciaro/object-path)) to [new optional chaining syntax](https://babeljs.io/docs/en/next/babel-plugin-proposal-optional-chaining.html) and remove unused object-path imports.
Downloads
3
Readme
babel-plugin-object-path-get-to-optional-chaining
This plugin replaces objectPath.get (object-path) to new optional chaining syntax and remove unused object-path imports.
WORKING ONLY WITH BABEL 7. THIS PLUGIN NOT WORKING WITH BABEL 6.
Install
Babel install:
npm install --save-dev @babel/core @babel/cli @babel/preset-env
Plugin install:
npm i -D babel-plugin-object-path-get-to-optional-chaining
Usage
.babelrc
{
"presets": [ "@babel/env" ],
"plugins": [
"object-path-get-to-optional-chaining"
]
}
./node_modules/.bin/babel src --out-dir src
Examples
from:
import objectPath from 'object-path'
objectPath.get(foo, 'bar.baz')
objectPath.get(foo.bar.baz.bar, 'baz')
objectPath.get(foo.bar, 'baz.bar')
to:
foo?.bar?.baz;
foo.bar.baz.bar?.baz;
foo.bar?.baz?.bar;
from:
import { get, set } from 'object-path'
get(foo, 'bar.baz')
get(foo.bar.baz.bar, 'baz')
get(foo.bar, 'baz.bar')
to:
import { set } from 'object-path';
foo?.bar?.baz;
foo.bar.baz.bar?.baz;
foo.bar?.baz?.bar;
from:
import { get } from 'object-path'
get(foo, 'bar.baz')
get(foo.bar.baz.bar, 'baz')
get(foo.bar, 'baz.bar')
to:
foo?.bar?.baz;
foo.bar.baz.bar?.baz;
foo.bar?.baz?.bar;
from:
import { get as objGet } from 'object-path'
objGet(foo, 'bar.baz')
objGet(foo.bar.baz.bar, 'baz')
objGet(foo.bar, 'baz.bar')
to:
foo?.bar?.baz;
foo.bar.baz.bar?.baz;
foo.bar?.baz?.bar;
from:
import { get as objGet, set as objSet } from 'object-path'
objGet(foo, 'bar.baz')
objGet(foo.bar.baz.bar, 'baz')
objGet(foo.bar, 'baz.bar')
to:
import { set as objSet } from 'object-path';
foo?.bar?.baz;
foo.bar.baz.bar?.baz;
foo.bar?.baz?.bar;
from:
import objectPath, { get as objGet, set as objSet } from 'object-path'
objGet(foo, 'bar.baz')
objGet(foo.bar.baz.bar, 'baz')
objGet(foo.bar, 'baz.bar')
to:
import { set as objSet } from 'object-path';
foo?.bar?.baz;
foo.bar.baz.bar?.baz;
foo.bar?.baz?.bar;
from:
import objectPath, { get as objGet, set as objSet } from 'object-path'
objGet(foo, 'bar.baz')
objGet(foo.bar.baz.bar, 'baz')
objGet(foo.bar, 'baz.bar')
objectPath.set(foo, 'baz')
to:
import objectPath, { set as objSet } from 'object-path';
foo?.bar?.baz;
foo.bar.baz.bar?.baz;
foo.bar?.baz?.bar;
objectPath.set(foo, 'baz');
from:
import objectPath, { get as objGet, set as objSet } from 'object-path'
objGet(foo, 'bar.baz')
objGet(foo.bar.baz.bar, 'baz')
objGet(foo.bar, 'baz.bar')
objectPath[cond ? 'get' : 'set'](foo, 'bar')
to:
import objectPath, { set as objSet } from 'object-path';
foo?.bar?.baz;
foo.bar.baz.bar?.baz;
foo.bar?.baz?.bar;
objectPath[cond ? 'get' : 'set'](foo, 'bar');