import Validation, {ErrorMessages, Fields, Rules} from "./mod.ts";
const input = {
name: 'Doğukan Akkaya',
email: 'info@codethereal.com',
password: '1234',
password_confirmation: '1234',
url: 'codethereal.com',
address: [
{
name: 'Address line 1',
location: 'Turkey, Istanbul'
},
{
name: 'Address line 2',
location: 'Turkey, Istanbul'
}
],
detail: {
job: 'Software Developer',
salary: 10.000,
currency: 'USD'
},
status: 1,
numbers: [1,2,3,4,5,6]
}
const rules: Rules = {
name: 'string|required|max:25|min:5',
email: 'string|required|email',
password: 'string|required|min:8',
url: 'string|required|url',
address: {
name: 'string|required',
location: 'string|required'
},
detail: {
job: 'string',
salary: 'number',
currency: 'string|in:USD,EUR,TRY'
},
status: 'number|required|in:0,1',
numbers: 'required|array|max:5'
}
const fields: Fields = {
name: 'Name',
email: 'Email',
password: 'Password',
password_confirmation: 'Password Confirmation',
address: {
name: 'Address Name',
location: 'Address Location'
},
detail: {
job: 'Job',
salary: 'Salary',
currency: 'Currency'
},
status: 'Status'
}
const customErrorMessages: ErrorMessages = JSON.parse(Deno.readTextFileSync("./en.json"))
const validation = new Validation(customErrorMessages)
const errors = validation
.validate(input, rules, fields)
.single('abc', 'min:5', 'test')
.getErrors()
if (errors.length > 0) {
console.log(errors)
} else {
console.log('There is no error')
}