wilmoore / selectn.js

Curried property accessor function that resolves deeply-nested object properties via dot/bracket-notation string path while mitigating TypeErrors via friendly and composable API.
https://www.npmjs.com/package/selectn
MIT License
196 stars 16 forks source link

Support dots in name at any point #78

Closed Nokel81 closed 6 years ago

Nokel81 commented 6 years ago

What would be really nice is if the follow could be done:

var obj = {
    'a.b': {
        'c': 5
    }
};

selectn('a.b.c', obj, {tryEverything: true });
// => 5

With tryEverything enabled (or something similar) then it would so a sort of "smart" search through the object, greedily trying to find the path to the object. Namely, a is not found so it then tries a.b which is finds and then goes onto find c. Would this be something that this library might want to support?

wilmoore commented 6 years ago

Hey @Nokel81 - I LOVE the idea of the suggested functionality.

That being said, it is not a feature that keeps with the spirit of the original design of selectn. If you (or anyone else reading this) know of or decide to create such a lib, feel free to link it here as I could imagine use cases for such a tool.

❤️

Nokel81 commented 6 years ago

Here you are: https://www.npmjs.com/package/dotfind

If you think anything should be added just open an issue on github

Nokel81 commented 6 years ago

I created it because I had looked through libs and could not find one that did this

Nokel81 commented 6 years ago

Since you thought that this would be useful would you mind adding it to the list of related packages?