sindresorhus / dot-prop

Get, set, or delete a property from a nested object using a dot path

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

deepKeys returns strange result

AuthorProxy opened this issue · comments

deepKeys({ x: 1, y: "1", z: [1], zz: [], o: {}, n: null, u: undefined, nan: NaN })

returns

['x', 'y', 'z[0]', 'n', 'u', 'nan']

Why is it missing zz and o, for me it is looks as bug

Working as intended. It would be inconsistent to only return the keys of arrays and objects when and only when they are empty.

@Richienb I use this library to get changed fields for modified objects and use it next to show validation messages, how did you decide what is inconsistent and what is not? Now whenever property become an empty array (for example I remove all elements from some list) it doesn't return me this key. For me inconsistent when method intended to grab object keys - doesn't return object keys. An empty array or object is the same as not empty array or object. Probably for you undefined or NaN or null is more consistent, than the array property, because they are works fine. I am not agree with you, I made a PR please check it.

@Richienb I look at it differently. All paths should be represented. Object/arrays are passthrough if the have children, but if not they are the path.