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

Added empty(obj, path) that also checks for object and arrays #51

Closed
wants to merge 2 commits into from

Conversation

ggedde
Copy link

@ggedde ggedde commented Feb 7, 2019

Added a simple method for checking whether the value is empty, but it also checks if the value is an object or array and if so checks if it has a .length

This makes for cleaner code:
Instead of:

const addOns = dotProp.get(data, 'cart.add_ons');
if( addOns && typeof addOns === 'object' && Object.keys(addOns).length) {
    // ...
}

You can now do:

if( !dotProp.empty(data, 'cart.add_ons')) {
    // ...
}

@sindresorhus
Copy link
Owner

I appreciate the PR, but this is not something I want in this package.

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

Successfully merging this pull request may close these issues.

None yet

2 participants