Zod

Usage with Flutter

TextFormField(
  validator: Zod().required().min(3).email().build,
)

All Validations

password
email
isEmails
min
max
equals
type<T>
required
cpf
cpnj
cpfCnpj
isDate
optional
custom

Usage with Shelf

// register user route

@Route.post('/register')
Future<Response> register (Request req) async {
  final data = jsonDecode(await req.readAsString());
  
  final requiredParams = {
    'email': Zod().email(),
    'password': Zod().password(),
    'data': {
      'user_name': Zod().min(8).max(20)
      'platform': Zod().type<String>(),
    },
  };

  final zod = Zod.validate(data: data, params: requiredParams);
  if (zod.isNotValid) {
    return Response(400, body: jsonEncode({
      'message': 'invalid params',
      'params': zod.result
    }))
  }

  // zod.result is a Map that contains the invalid parameters key, and a message
  
  // example: 
  // {
  //    'data': {
  //      'user_name': 'At least 8 characters'
  //    }
  // }

  ...
}


How change locale

Zod(localeZod: LocaleEN()).required().build,

// or

Zod.zodLocaleInstance = LocaleEN() // apply in all system

Create your Locale

class MyLocale implements ILocaleZod {
  // implement the required methods in ILocaleZod
}

Zod(localeZod: MyLocale()).required().build

Feito com ❤️ by Weliton Sousa

Libraries

zod_validation