Verify
public enum Verify<Subject>
Undocumented
-
Create a Validator from a predicate
e.g Verify<String>.that({ !$0.isEmpty }, otherwise: .requiredField) or Verify.that({ (String input) in !input.isEmpty }, otherwise: .requiredField)
-
Create a validator that acts on a specific property of the validated subject. Useful for validating structs and other composite types.
Declaration
Parameters
keyPath
A keypath selecting the property or attribue of the subject.
-
Creates a validator on optional from a validator
Note will only run the provided validator if the input is Optional.some
Declaration
Swift
public static func optional<T>(_ validator: ValidatorT<Subject, T>) -> ValidatorT<Subject?, T?>
-
Creates a validator composing the provided validators in a parallel way
Declaration
Parameters
validators
The list of validators to compose
merge
A function that can sum or select the final output of the resulting validator.
Note: Tipically subjects won’t be mutated of transformed in validating functions so output will be the same.
-
Creates a validator composing the provided validators in a parallel way
Declaration
Swift
public static func atOnce(@ValidationParallelBuilder<Subject> _ content: () -> Validator<Subject>) -> Validator<Subject>
Parameters
validators
The list of validators to compose
merge
A function that can sum or select the final output of the resulting validator.
Note: Tipically subjects won’t be mutated of transformed in validating functions so output will be the same.
-
Create a Validator by composing the provided validators in a sequential fashion.
Declaration
Parameters
validators
The validators to compose
Return Value
A validators the will either succeed or fails with exactly one error.
-
Create a Validator by composing the provided validators in a sequential fashion.
Note: This is essential the same as
inOrder
but using a function builder and not having to seperate items by commas.Declaration
Swift
public static func inOrder(@ValidationSequencedBuilder<Subject> _ content: () -> Validator<Subject>) -> Validator<Subject>
Parameters
content
The function builder body
Return Value
A validators the will either succeed or fails with exactly one error.
-
Creates a validator that always succeeds
Const validator that ignores its input.
Declaration
Swift
public static func valid(_ value: Subject) -> Validator<Subject>
Parameters
value
The value with which this validator should succeed.
-
Creates a validator that always fails with the provided error
Will fail no matter what input is provided
Declaration
Swift
public static func error(_ error: Error) -> Validator<Subject>
Parameters
error
The error to fail with
Return Value
Validator
-
Undocumented
Declaration
Swift
public static func greaterThanZero(otherwise error: Error) -> Validator<Subject>
-
Create a validator on String testing its length to be greater or equal to a value.
Declaration
Swift
public static func minLength(_ value: Int, otherwise error: Error) -> Validator<Subject>
Parameters
value
Integer representing the minimum length this string should have
error
The error in case length criteria not fulfilled.
-
Create a validator on String testing its length to be less than or equal to a value.
Declaration
Swift
public static func maxLength(_ value: Int, otherwise error: Error) -> Validator<Subject>
Parameters
value
Integer representing the minimum length this string should have
error
The error in case length criteria not fulfilled.
-
Creates a validator that ensures no overlap between the tested string and the provided CharacterSet
Declaration
Swift
public static func dissallowedCharacterSet(_ set: CharacterSet, otherwise error: Error) -> Validator<Subject>
Parameters
set
Character set to test the string against
error
The error in case the string is not disjoint with the set.
-
Creates a validator that ensures input is a subset of the provided CharacterSet.
Declaration
Swift
public static func fromCharacterSet(_ set: CharacterSet, otherwise error: Error) -> Validator< Subject >
Parameters
set
Character set to test the string against
error
The error in case the string is not disjoint with the set.
-
Creates a validator that ensures input is a subset of the provided CharacterSet.
Declaration
Swift
public static func containsSomeOf(_ set: CharacterSet, otherwise error: Error) -> Validator< Subject >
Parameters
set
Character set to test the string against
error
The error in case the string is not disjoint with the set.
-
Creates a validator from a regular expression
Note the regex should have exactly one match and it should be over the range of the complete string.
Declaration
Swift
public static func matchesRegex(_ regex: NSRegularExpression, otherwise error: Error) -> Validator<Subject>
Parameters
regex
Regular expression to test the string against.
error
Failure to if string does not match.