Transform object string dot notation into object reference
Transform object string dot notation into object reference
@themgoncalves/transform-object-dot-notation"">
const obj = {
foo: {
bar: {
baz: {
val: 'hello world',
},
},
},
};
const val = obj['foo.bar.baz.val'] // hello world
const obj = {
foo: {
bar: {
baz: class {
},
},
},
};
const baz = new obj['foo.bar.baz'] // baz instance
const obj = {
foo: {
bar: {
baz: function() {
return 'hello world'
},
},
},
};
const baz = obj['foo.bar.baz']() // hello world
Optional Chaining
Proposal
const obj = {
foo: {
bar: {
baz: 30,
},
},
};
const safe = obj['foo?.quiz?.baz'] // undefined
In this case, transform-object-dot-notation
should be placed before @babel/plugin-proposal-optional-chaining
npm install --save-dev @themgoncalves/transform-object-dot-notation
Note: transform-object-dot-notation
should be listed in the devDependencies
.
.babelrc
(Recommended).babelrc
{
"plugins": ["@themgoncalves/transform-object-dot-notation"]
}
$ babel --plugins @themgoncalves/transform-object-dot-notation script.js
require("@babel/core").transform("code", {
plugins: ["@themgoncalves/transform-object-dot-notation"]
});
optional chaining
transformoptionalChaining
option. Usage no longer requires settings specification.optionalChaining
optionMarcos Gonçalves – LinkedIn – Website
Distributed under the MIT license. Click here for more information.
https://github.com/themgoncalves/transform-object-dot-notation
git checkout -b feature/fooBar
)git commit -m '
Add some fooBar'
)git push origin feature/fooBar
)