Skip to content

Conversation

@bwendt-mylo
Copy link

I'm often needing to drill into arrays within nested objects and have paths like the following:

values.conditions[1].operator

This PR adds the ability for dlv to accept these types of paths, doing a greedy split on word boundaries instead of splitting on dot. Minimal increase in size to 132b.

cc @developit

@bstillwagon-mylo
Copy link

@developit Any chance you could take a look at this PR? It would be very helpful!

@ajoslin
Copy link

ajoslin commented Nov 5, 2018

Just use values.conditions.1.operator

@developit
Copy link
Owner

Indeed - any reason values.conditions.1.operator doesn't work for you @bwendt-mylo? You can also pass an Array: dlv(obj, ['values', 'conditions', 1, 'operator']).

@bwendt-mylo
Copy link
Author

I do use the existing methods, and they work fine. This would just be a convenience thing when using libraries like redux-form where you get dot-and-bracket paths like:

contact.billing.address[2].phones[1].areaCode

@developit
Copy link
Owner

Gotcha. The solution of splitting on non-word characters is really clever, but it breaks for a bunch of property names:

dlv(obj, 'foo.some property') // should be equivalent to obj.foo['some property']

@bwendt-mylo
Copy link
Author

Are you open to modifications to the PR to add more flexibility/account for the edge cases or do you not feel like it's worth the added complexity at this point?

@bwendt-mylo
Copy link
Author

@developit @ajoslin The more I've tried to find a suitable pattern/workaround for this problem the more I realize that's terribly hard and won't stay tiny. Thanks for entertaining the idea.

aarondancer added a commit to aarondancer/dlv that referenced this pull request May 14, 2019
Huge thanks to @bwendt-mylo for writing this previously in developit#24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants