All Projects → digiacomo → Fluidvalidator

digiacomo / Fluidvalidator

Licence: mit
General purpose validation system for objects, nested objects, enumerables written in Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Fluidvalidator

Validot
Validot is a performance-first, compact library for advanced model validation. Using a simple declarative fluent interface, it efficiently handles classes, structs, nested members, collections, nullables, plus any relation or combination of them. It also supports translations, custom logic extensions with tests, and DI containers.
Stars: ✭ 198 (+122.47%)
Mutual labels:  validation, validation-library
thai-citizen-id-validator
🦉 Validate Thai Citizen ID with 0 dependencies 🇹🇭
Stars: ✭ 35 (-60.67%)
Mutual labels:  validation, validation-library
Php Validate
Lightweight and feature-rich PHP validation and filtering library. Support scene grouping, pre-filtering, array checking, custom validators, custom messages. 轻量且功能丰富的PHP验证、过滤库。支持场景分组,前置过滤,数组检查,自定义验证器,自定义消息。
Stars: ✭ 225 (+152.81%)
Mutual labels:  validation, validation-library
Validator
Drop in user input validation for your iOS apps.
Stars: ✭ 1,444 (+1522.47%)
Mutual labels:  validation, validation-library
Govalidator
[Go] Package of validators and sanitizers for strings, numerics, slices and structs
Stars: ✭ 5,163 (+5701.12%)
Mutual labels:  validation, validation-library
Deep Waters
🔥Deep Waters is an easy-to-compose functional validation system for javascript developers 🔥
Stars: ✭ 188 (+111.24%)
Mutual labels:  validation, validation-library
valify
Validates data in JavaScript in a very simple way
Stars: ✭ 13 (-85.39%)
Mutual labels:  validation, validation-library
Typescript Runtime Type Benchmarks
Benchmark Comparison of Packages with Runtime Validation and TypeScript Support
Stars: ✭ 119 (+33.71%)
Mutual labels:  validation, validation-library
Validator Docs
Validação de CPF, CNPJ, CNH, NIS, Título Eleitoral e Cartão Nacional de Saúde com Laravel.
Stars: ✭ 334 (+275.28%)
Mutual labels:  validation, validation-library
Easyvalidation
✔️ A text and input validation library in Kotlin for Android
Stars: ✭ 328 (+268.54%)
Mutual labels:  validation, validation-library
Validator Collection
Python library of 60+ commonly-used validator functions
Stars: ✭ 91 (+2.25%)
Mutual labels:  validation, validation-library
Lcformvalidation
Javascript based form validation library, third party library / framework agnostic.
Stars: ✭ 58 (-34.83%)
Mutual labels:  validation, validation-library
Password Validator
Validates password according to flexible and intuitive specification
Stars: ✭ 224 (+151.69%)
Mutual labels:  validation, validation-library
Valiktor
Valiktor is a type-safe, powerful and extensible fluent DSL to validate objects in Kotlin
Stars: ✭ 267 (+200%)
Mutual labels:  validation, validation-library
Laravel Vue Validator
Simple package to display error in vue from laravel validation
Stars: ✭ 32 (-64.04%)
Mutual labels:  validation, validation-library
Vee Validate
✅ Form Validation for Vue.js
Stars: ✭ 8,820 (+9810.11%)
Mutual labels:  validation, validation-library
React Required If
React PropType to conditionally add `.isRequired` based on other props
Stars: ✭ 72 (-19.1%)
Mutual labels:  validation
Vue Rawmodel
RawModel.js plugin for Vue.js v2. Form validation has never been easier!
Stars: ✭ 79 (-11.24%)
Mutual labels:  validation
Angular Validate
Painless form validation for AngularJS. Powered by the jQuery Validation Plugin.
Stars: ✭ 71 (-20.22%)
Mutual labels:  validation
Unicorn
Unicorn - W3C's Unified Validator
Stars: ✭ 70 (-21.35%)
Mutual labels:  validation

FluidValidator

CI Status Version License Platform

Description

FluidValidator is intended to encapsulate validation logic. The API was designed with FluentValidation (https://github.com/JeremySkinner/FluentValidation) and Rails Validation as reference. Currently offers validation of simple objects, complex objects (object graph), enumerables. Localized error messages. You can easly override base behaviors and/or build your own reusable validation rules.

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

No special requirements

Installation

FluidValidator is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "FluidValidator"

Usage

A simple object

Given this object:

import Foundation

class Home {
    var isLocked:Bool?
    var number:Int?
    var ownerName:String?
}

Create a custom validator extending AbstractValidator specifing target class Example:

import Foundation
import FluidValidator

class HomeValidator : AbstractValidator<Home> {
    override init() {
        super.init()
               
        self.addValidation(withName: "number") { (context) -> (Any?) in
            context.number
        }.addRule(GreaterThan(limit: 3, includeLimit: false))
        
        self.addValidation(withName: "ownerName") { (context) -> (Any?) in
            context.ownerName
        }.addRule(BeNotEmpty())
        
        self.addValidation(withName: "isLocked") { (context) -> (Any?) in
            context.isLocked
        }.addRule(BeTrue())
    }
}

Nested Objects

Given this more complex object:

import Foundation

class Home {
    var isLocked:Bool?
    var number:Int?
    var ownerName:String?
    var garage: Garage?
}
class Garage {
  var isOpen: Bool?
  var maxCars: Int?
}

The corresponding validator would be implemented this way:

import Foundation
import FluidValidator

class GarageValidator: AbstractValidator<Garage> {
    override init() {
        super.init()
        
        self.addValidation(withName: "isOpen") { (context) -> Any? in
            context.isOpen
        }.addRule(BeTrue())
        
        self.addValidation(withName: "maxCars") { (context) -> Any? in
            context.maxCars
        }.addRule(LessThan(limit: 2, includeLimit: true))
    }
}

class HomeValidator : AbstractValidator<Home> {
    override init() {
        super.init()
        
        ...
        self.addValidation(withName: "garage") { (context) -> (Any?) in
            context.garage
        }.addRule(GarageValidator())
    }
}

Run validations and get result

regardless of your validators complexity, you can run validation process and extract error messages (if any) as showed here

    let garage = Garage()
    garage.isOpen = false

    let home = Home()
    home.isLocked = true
    home.ownerName = "John Doe"
    home.number = 2
    home.garage = garage

    let homeValidator = HomeValidator()
    let result = homeValidator.validate(home)
    let failMessage = homeValidator.allErrors()

Get fail messages

failMessage.failMessageForPath("number")?.errors.first?.compact
failMessage.failMessageForPath("number")?.errors.first?.extended

failMessage.failMessageForPath("garage")?.errors.first?.compact
failMessage.failMessageForPath("garage.isOpen")?.errors.first?.extended

The errors array contains ErrorMessage objects which in turn contains compact and extended error message.

Take a look at Unit Test classes to figure out other features

Author

FrogRain, [email protected]

License

FluidValidator is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].