0.1.2 • Published 7 years ago
@themgoncalves/transform-object-dot-notation v0.1.2
transform-object-dot-notation
Transform object string dot notation into object reference
Example
Accessing deeply nested properties
const obj = {
foo: {
bar: {
baz: {
val: 'hello world',
},
},
},
};
const val = obj['foo.bar.baz.val'] // hello worldCalling deeply nested functions
const obj = {
foo: {
bar: {
baz: class {
},
},
},
};
const baz = new obj['foo.bar.baz'] // baz instanceConstructing deeply nested classes
const obj = {
foo: {
bar: {
baz: function() {
return 'hello world'
},
},
},
};
const baz = obj['foo.bar.baz']() // hello worldWith Optional Chaining Proposal
const obj = {
foo: {
bar: {
baz: 30,
},
},
};
const safe = obj['foo?.quiz?.baz'] // undefinedIn this case, transform-object-dot-notation should be placed before @babel/plugin-proposal-optional-chaining
Installation
npm install --save-dev @themgoncalves/transform-object-dot-notationNote: transform-object-dot-notation should be listed in the devDependencies.
Usage
Via .babelrc (Recommended)
.babelrc
{
"plugins": ["@themgoncalves/transform-object-dot-notation"]
}Via CLI
$ babel --plugins @themgoncalves/transform-object-dot-notation script.jsVia Node API
require("@babel/core").transform("code", {
plugins: ["@themgoncalves/transform-object-dot-notation"]
});Release History
- 0.1.2
- FIX:
optional chainingtransform - DEPRECATE:
optionalChainingoption. Usage no longer requires settings specification.
- FIX:
- 0.1.1
- First release
- NEW:
optionalChainingoption
- 0.0.1
- Work in progress
Meta
Author
Marcos Gonçalves – LinkedIn – Website
License
Distributed under the MIT license. Click here for more information.
https://github.com/themgoncalves/transform-object-dot-notation
Contributing
- Fork it (https://github.com/themgoncalves/transform-object-dot-notation/fork)
- Create your feature branch (
git checkout -b feature/fooBar) - Commit your changes (
git commit -m ':zap: Add some fooBar') - Push to the branch (
git push origin feature/fooBar) - Create a new Pull Request