Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// @flow
import type { ValidateResponse } from './types';
const Validator = require('validatorjs');
Validator.useLang('zh');
/**
* Description 自定义校验规则,!本部分是使用了 validatorjs 作为内部实现
* @param data
* @param rules
* @param customMessage
* @return ValidateResponse
*/
export function validate(
data: any,
rules: {
[string]: string | []
},
customMessage: {
[string]: string
} = undefined
validator.passes(() => {})
var fails: boolean = validator.fails() as boolean
validator.fails(() => {})
var check: boolean = validator.check()
var errors: Validator.Errors = validator.errors
var all: Validator.ValidationErrors = errors.all()
var error: Array = errors.get("foo")
var first: string | boolean = errors.first("foo")
var has: boolean = errors.has("foo")
Validator.setMessages("en", {})
var messages: Validator.ErrorMessages = Validator.getMessages("en")
Validator.useLang("en")
var lang: string = Validator.getDefaultLang()
Validator.setAttributeFormatter((attributes: any) => ({}))
Validator.stopOnError(true)
Validator.register("custom", () => {}, "error.custom")
Validator.registerAsync("custom", () => {}, "error.custom")
export function configureValidatorjs(configParameters: IValidatorjsConfiguration): void {
if (configParameters.language) {
Validator.useLang(configParameters.language);
}
if (configParameters.setAttributeFormatter) {
Validator.setAttributeFormatter(configParameters.setAttributeFormatter);
}
}
export function configureValidatorjs(configParameters: IValidatorjsConfiguration): void {
if (configParameters.language) {
Validator.useLang(configParameters.language);
}
if (configParameters.setAttributeFormatter) {
Validator.setAttributeFormatter(configParameters.setAttributeFormatter);
}
}