class-validator
class-validator copied to clipboard
feature: add `isNotBlank` decorator
Description
we often need to check a string variable is not a empty or Map is not empty or Set is not empty
Proposed solution
function isBlank(val:string|Array<any>|Map<string,any>|Set<any>){
if(val instanceof Array || val instanceof String){
if(isTypes.isArray(val) || isTypes.isString(val)){
return val.length == 0;
}
}else if(val instanceof Set || val instanceof Map){
if(isTypes.isMap(val) || isTypes.isSet(val)){
return val.size == 0;
}
}
}
We use javax.validation on the server side, and try to also validate on the client side. There we have https://javaee.github.io/javaee-spec/javadocs/javax/validation/constraints/NotEmpty.html and https://javaee.github.io/javaee-spec/javadocs/javax/validation/constraints/NotBlank.html.
Maybe the existing IsEmpty/IsNotEmpty decorators should also evaluate Arrays, Sets and Maps, and IsBlank/IsNotBlank should just evaluate strings and should trim() the string before checking.
seems useful to me ;)