项目作者: themgoncalves

项目描述 :
Transform object string dot notation into object reference
高级语言: JavaScript
项目地址: git://github.com/themgoncalves/transform-object-dot-notation.git
创建时间: 2019-03-22T15:27:51Z
项目社区:https://github.com/themgoncalves/transform-object-dot-notation

开源协议:MIT License

下载


transform-object-dot-notation

Transform object string dot notation into object reference

@themgoncalves/transform-object-dot-notation"">NPM
CircleCI
GitHub All Releases
GitHub stars
Known Vulnerabilities
GitHub issues
Awesome

Example

Accessing deeply nested properties

  1. const obj = {
  2. foo: {
  3. bar: {
  4. baz: {
  5. val: 'hello world',
  6. },
  7. },
  8. },
  9. };
  10. const val = obj['foo.bar.baz.val'] // hello world

Calling deeply nested functions

  1. const obj = {
  2. foo: {
  3. bar: {
  4. baz: class {
  5. },
  6. },
  7. },
  8. };
  9. const baz = new obj['foo.bar.baz'] // baz instance

Constructing deeply nested classes

  1. const obj = {
  2. foo: {
  3. bar: {
  4. baz: function() {
  5. return 'hello world'
  6. },
  7. },
  8. },
  9. };
  10. const baz = obj['foo.bar.baz']() // hello world

With Optional Chaining Proposal

  1. const obj = {
  2. foo: {
  3. bar: {
  4. baz: 30,
  5. },
  6. },
  7. };
  8. const safe = obj['foo?.quiz?.baz'] // undefined

In this case, transform-object-dot-notation should be placed before @babel/plugin-proposal-optional-chaining


Installation

  1. npm install --save-dev @themgoncalves/transform-object-dot-notation

Note: transform-object-dot-notation should be listed in the devDependencies.


Usage

.babelrc

  1. {
  2. "plugins": ["@themgoncalves/transform-object-dot-notation"]
  3. }


Via CLI

  1. $ babel --plugins @themgoncalves/transform-object-dot-notation script.js

Via Node API

  1. require("@babel/core").transform("code", {
  2. plugins: ["@themgoncalves/transform-object-dot-notation"]
  3. });


Release History

  • 0.1.2
    • FIX: optional chaining transform
    • DEPRECATE: optionalChaining option. Usage no longer requires settings specification.
  • 0.1.1
    • First release
    • NEW: optionalChaining option
  • 0.0.1
    • Work in progress


Meta

Author

Marcos GonçalvesLinkedInWebsite

License

Distributed under the MIT license. Click here for more information.

https://github.com/themgoncalves/transform-object-dot-notation

Contributing

  1. Fork it (https://github.com/themgoncalves/transform-object-dot-notation/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -m ':zap: Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request