-
Notifications
You must be signed in to change notification settings - Fork 625
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
Add is.present #278
Comments
It's really useful for confirming ensuring the data you're about to use is there, in a concise way. So, this code, which has to check that an array has been returned from the server before it can check if it contains anything:
Now does the same check in one step, because both null and [] will return false:
|
can be a |
They don't have the same functionality. To be present something must be both truthy and not blank. Empty arrays and objects are truthy, empty strings are falsy. All three are empty and therefor not present. Also, |
I would love to see an
is.present()
function, like thepresent?
method in Rails. Basically, it returns true if the value is truthy and not empty. So an empty array, object, or string would not be present, nor would null, undefined, and NaN.The text was updated successfully, but these errors were encountered: