Add a query filter for empty value
This is a proposal to make querying for empty values easier. Handling all possible edge cases
There should be a query filter to handle possible empty values; in situations where we need to
unset
a property and filter by this property, this filter should consider all possible falsey value, something similar to lodash's isEmpty
https://lodash.com/docs/4.17.15#isEmpty
This may be opionionated but I think there are a few people who see value in this...
For array types => []
For object => {}
For string "" (not to be confused with " ", an empty space; We can consider both instance as falsey
but I need to hear people's suggestions if this makes sense)
For numbers => 0
It should also apply to null
, undefined
and NaN
Instead of doing things like this
This new approach is cleaner and would automatically handle edge cases. When the field is an object
and this object is empty, it returns as part of the results; for an array, when it's empty or the length is 0, this also applies; same with null
, undefined
, false
and 0
Open to questions and why this may not be a good thing.
More: https://developer.mozilla.org/en-US/docs/Glossary/FalsyMDN Web Docs
Falsy - MDN Web Docs Glossary: Definitions of Web-related terms | MDN
A falsy (sometimes written falsey) value is a value that is considered false when encountered in a Boolean context.
1 Reply
you could write your own helper for this, something like: