Skip to content

emersonbroga/Honour

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Honour

Language License Version

Validation library for iOS inspired by Respect/Validation.

Validator.mustBe(Uppercase()).andMust(StartsWith("F")).validate("FOOBAR")

Usage

Single Validation

let username = "jeanpimentel"
Lowercase().validate(username) // true

Chained Validation

It is possible to use validators in a chain.

let v = Validator.addRule(Lowercase()).addRule(NoWhitespace()).addRule(Length(min: 3, max: 60))
v.validate("jeanpimentel") // true

Syntax sugar

It is possible to use some syntax tricks to be highly expressive.

let v = Validator.mustHave(Length(min: 3, max: 60)).and(NoWhitespace()).andMustBe(Lowercase())
v.validate("jeanpimentel") // true

Granularity control

We have 3 validation methods

  • validate() - returns true or false
  • assert() - returns a tuple with true/false and all errors, if any.
  • check() - returns a tuple with true/false and the first error, if any.

Validate

func validate(value: String) -> Bool
let validator = Validator().addRule(Uppercase()).addRule(StartsWith("J"))
validator.validate("JEAN") // true
validator.validate("PIMENTEL") // false

Assert

func assert(value: String) -> (isValid: Bool, invalidRules: Array<Rule>)
let validator = Validator().addRule(Uppercase()).addRule(StartsWith("J"))

let result = validator.assert("JEAN")
result.isValid      // true
result.invalidRules // [] (empty)

let result = validator.assert("Jean")
result.isValid      // false
result.invalidRules // [Uppercase()]

let result = validator.assert("Felipe")
result.isValid      // false
result.invalidRules // [Uppercase(), StartsWith("J")]

Check

func check(value: String) -> (isValid: Bool, invalidRule: Rule?)
let validator = Validator().addRule(Uppercase()).addRule(StartsWith("J"))

let result = validator.check("JEAN")
result.isValid     // true
result.invalidRule // nil

let result = validator.check("Felipe")
result.isValid     // false
result.invalidRule // Uppercase()

let result = validator.check("FELIPE")
result.isValid     // false
result.invalidRule // StartsWith("J")

Installation

Package is available on Cocoapods. See the "Using CocoaPods" guide for more information.

use_frameworks!
platform :ios, '7.0'
pod 'Honour', '~> 0.1.0'

Requirements

Honour Version Minimum iOS Target Notes
0.1.0 iOS 7 Xcode 6.3 (Swift 1.2) is required.

Contributing

  • If you found a bug, and can provide steps to reliably reproduce it, open an issue.

  • If you have a feature request, open an issue.

  • If you want to contribute, submit a pull request.

    1. Fork it!
    2. Create your feature branch: git checkout -b my-new-feature
    3. Commit your changes: git commit -am 'Add some feature'
    4. Push to the branch: git push origin my-new-feature
    5. Submit a pull request

Validators

Working in progress...

Implemented:

  • Contains
  • EndsWith
  • Length
  • Lowercase
  • StartsWith
  • Uppercase

License

Honour is released under the MIT license. See LICENSE for details.

About

iOS Validation Library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 97.5%
  • Ruby 1.9%
  • Makefile 0.6%