dlv icon indicating copy to clipboard operation
dlv copied to clipboard

Square bracket syntax support

Open aarondancer opened this issue 6 years ago • 2 comments

I realize that this was already attempted in #24, but with a little extra work I was able to support the edge cases mentioned in the thread.

I tested these changes against the lodash.get tests and it's mostly compatible. The lodash.get tests failing all seem like uncommon edge-cases, so I've opted not to address them.

The following tests from lodash.get fail:

`dlv` should preserve the sign of `0`
`dlv` should get symbol keyed property values
`dlv` should get a key over a path
`dlv` should not ignore empty brackets
`dlv` should handle empty paths
`dlv` should handle complex paths
`dlv` should follow `path` over non-plain objects
`dlv` should return the default value when `path` is empty

This will also address #27

cc @developit @bwendt-mylo

aarondancer avatar May 14 '19 16:05 aarondancer

Hey @aarondancer! Thanks for opening the PR. Would you be able to provide some context on why square bracket notation is important for your use-case?

developit avatar May 22 '19 12:05 developit

I dare say it make's composing array like indices easier to reason about. Like "im indexing an array, as opposed to accessing a property"... but imo you may very just go dlv(obj, 'a.b.0.c'); dlv(obj2, 'a.b.1.c');, which keep the bundle size down too, and avoids regex.

maraisr avatar May 23 '19 01:05 maraisr