Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use underscore.js to find if a String is blank?

I am looking an equivalent of http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#isBlank(java.lang.CharSequence) I found several 3rd party extensions, but is there one out of the box with underscore.js: http://underscorejs.org

like image 663
Sudheer Aedama Avatar asked Sep 17 '14 21:09

Sudheer Aedama


1 Answers

function isBlank(str) {
  return !!(str||'').match(/^\s*$/);
}

isBlank(null);    // => true
isBlank('');      // => true
isBlank(' \t ');  // => true
isBlank(' foo '); // => false
like image 136
maerics Avatar answered Sep 18 '22 03:09

maerics