Hi! Thanks for helping me put bread on my family's table!
Anyhow, I found the isBlank() semantics pretty useful back in the day when doing Java coding with Commons Lang. I looked for it today in lodash and when I found it wasn't there I rolled my own with _.isString() and _.trim() and length > 0.
Here's the function I'm thinking about:
https://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/StringUtils.html#isBlank%28java.lang.CharSequence%29
Perhaps our take on _.isBlank() could fallback to _.isEmpty() semantics for non-String types.
I think you're on the right track with _.trim. Usually you want to cleanup your data and then perform checks. In this case if you _.trim your result would end up being falsey for blank strings anyways.
Oh yeah, empty strings are falsey! I always hated that about strings, and now it's finally useful. ;)
So, just return _.isString(s) ? !!_.trim(s) : _.isEmpty(s);
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Oh yeah, empty strings are falsey! I always hated that about strings, and now it's finally useful. ;)
So, just
return _.isString(s) ? !!_.trim(s) : _.isEmpty(s);