1.3.2 • Published 4 months ago
koatty_validation v1.3.2
koatty_validation
Validation Util for Koatty. Based on class-validator, extended parameter type checking and restricted attribute functions.
User Decorators
- @IsDefined
- @IsCnName
- @IsIdNumber
- @IsZipCode
- @IsMobile
- @IsPlateNumber
- @IsEmail
- @IsIP
- @IsPhoneNumber
- @IsUrl
- @IsHash
- @IsNotEmpty
- @Equals
- @NotEquals
- @Contains
- @IsIn
- @IsNotIn
- @IsDate
- @Gt
- @Gte
- @Lt
@Lte
@Valid
- @Validated
export class Controller {
Test(@Valid("IsNotEmpty", "can not be empty!!") id: number){
//todo
}
@Validated() // use dto validation
TestDto(user: UserDTO) {
}
}
export class UserDTO {
@IsNotEmpty({ message: "can not be empty!!" })
phoneNum: string;
@IsCnName({ message: "must be cn name"})
userName: string;
}
Validator for manual
FunctionValidator
- IsCnName
- IsIdNumber
- IsZipCode
- IsMobile
- IsPlateNumber
- IsEmail
- IsIP
- IsPhoneNumber
- IsUrl
- IsHash
- IsNotEmpty
- Equals
- NotEquals
- Contains
- IsIn
- IsNotIn
- IsDate
- Gt
- Gte
- Lt
- Lte
exp:
const str = "";
// throw Error
FunctionValidator.IsNotEmpty(str, "cannot be empty");
FunctionValidator.Contains(str, {message: "must contain s", value: "s"});
//
if (!ValidFuncs.IsNotEmpty(str)) {
console.log("empty");
}
ClassValidator
exp:
class SchemaClass {
@IsDefined
id: number;
@IsNotEmpty
name: string;
}
ClassValidator.valid(SchemaClass, {name: ''}).catch(err => {
console.log(err);
})
1.3.2
4 months ago
1.3.1
4 months ago
1.3.0
4 months ago
1.2.10
5 months ago
1.2.9
8 months ago
1.2.8
1 year ago
1.2.7
1 year ago
1.2.6
1 year ago
1.2.5
2 years ago
1.2.4
2 years ago
1.2.3
2 years ago
1.2.0
2 years ago
1.2.2
2 years ago
1.1.0
2 years ago
1.0.12
2 years ago
1.0.10
2 years ago
1.0.8
2 years ago
1.0.6
2 years ago
1.0.4
3 years ago
1.0.2
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago