-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot pick value from object if key contains dot #37
Comments
A key with dots is ambiguous, e.g how should this work: const object = {
foo: {
bar: 'baz',
},
'foo.bar': 'baz,
} Perhaps adding an escape makes sense? (not currently supported) dot.pick('foo\.bar', object) |
I do not think that escaping would make sense since some strings and objects may come from an external source that is not aware of the plugin. How about this: const object = {
foo: {
bar: 'one'
}
'foo.bar': 'two',
'some.thing': 'three'
};
dot.pick('foo.bar', object); // "one"
dot.pick('some.thing', object); // "three"
object['foo.bar']; // "two" We could prefer sub-properties to dotted properties since they are way more frequent. So, if there is an ambiguous situation, this would need additional code by the developer. And I think that it would be simpler to implement. As soon as the property cannot be resolved, we go with the next iteration and concatenate the previous key with the current one. |
Perhaps it's better to solve it in your own code: const value = object['foo.bar'] || dot.pick('foo.bar', object); For the other methods like set, move transfer etc. the behavior would become rather unpredictable. |
Sorry to reopen this here: @rhalff you mention "it's better to solve it in your own code" but we don't always know the object schema.
This is similar to what I would do in code, and it should cover scenarios where the property has spaces and characters that might be used as alternative separators https://github.com/rhalff/dot-object#using-a-different-separator This could work interchangeably, even for non-dotted properties:
|
As a developer, I want to be able to pick a value from an object if the key contains dots.
Currently, I am receiving
undefined
instead ofbaz
.The text was updated successfully, but these errors were encountered: