@deot/helper-validator
v1.1.3
Published
### `Validator` ```js import { Validator } from '@deot/helper-validator';
Downloads
8
Readme
@deot/helper-validator
Validator
import { Validator } from '@deot/helper-validator';
// or
import { Validator } from '@deot/helper';
- 示例
const validator = new Validator({
age: [
{
message: message1,
// async
validate: (value) => {
return value < 30 ? Promise.reject('age < 30') : Promise.resolve();
}
},
{
message: message2,
// sync
validate: (value) => {
return value > 16;
}
}
]
});
try {
await validator.validate({ age: 25 });
console.log('pass');
} catch (errors: ValidateError[]) {
console.log(errors);
}