I am working on a generic isBlank function in JS like Java StringUtils.isBlank();
I would like your opinion on the implementation in case I missed something like == vs === or better implementation?
so the following are considerd blank:
var a; //undefined => true
var b = null; //null => true
var c = ''; //emptyString => true
var d = ''; //emptyString => true
var e = ' \b \f \n \r \t \v \0 '; //emptyString with other white space => true
Implementation:
function isBlank(value){
return(value == undefined || value == null || value.trim() == '');
}
var a; //undefined => true
var b = null; //null => true
var c = ''; //emptyString => true
var d = ''; //emptyString => true
var d1 = ' \b \f \n \r \t \v \0 ';
var e = 'X'; //char => false
var f = '#'; //char => false
var g = '1'; //digit => false
function isBlank(value){
return(value == undefined || value == null || value.trim() == '');
}
console.log('a => ' + isBlank(a));
console.log('b => ' + isBlank(b));
console.log('c => ' + isBlank(c));
console.log('d => ' + isBlank(d));
console.log('d1 => ' + isBlank(d1));
console.log('e => ' + isBlank(e));
console.log('f => ' + isBlank(f));
console.log('g => ' + isBlank(g));