Skip to content
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

undefined key throws #35

Open
mikesherov opened this issue May 23, 2019 · 4 comments
Open

undefined key throws #35

mikesherov opened this issue May 23, 2019 · 4 comments
Labels

Comments

@mikesherov
Copy link

From the readme:

//undefined obj or key returns undefined, unless a default is supplied
delve(undefined, 'a.b.c') === undefined;
delve(undefined, 'a.b.c', 'foo') === 'foo';
delve(obj, undefined, 'foo') === 'foo';
@developit
Copy link
Owner

Likely broken by the inclusion of Array support. TBH I'm not sure if there's a better behaviour here - undefined could only really be stringified, which is super unintuitive. I'd kinda rather have it throw.

@mikesherov
Copy link
Author

I agree. So should the docs be updated?

@lfre
Copy link

lfre commented Feb 18, 2021

I ran across this recently in styled-system, and looked familiar. https://github.com/styled-system/styled-system/blob/6e00a16e0c53d865955c03df2d8d6ade8948bb2f/packages/core/src/index.js#L35

key = key && key.split ? key.split('.') : [key] seems to do the trick. thoughts @developit ?

@Aaronphy
Copy link

delve(undefined || {}, 'a.b.c') === undefined

I think adding a default obj will be ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants