(assign-names errors selectors-to-names)
translate
expects each field to have a human readable name. assign-names
takes a collection of errors and a map of selectors to names and will return
the errors with names inserted.
`translate` expects each field to have a human readable name. `assign-names` takes a collection of errors and a map of selectors to names and will return the errors with names inserted.
(attr selector)
(attr selector validation)
Runs a validation on the data found at selector
. If there are nested uses
of attr
any :selector
attributes in errors will be updated to reflect the
full selector
.
Example:
(validate (attr [:name] (present)) {:name "Vlad"})
Runs a validation on the data found at `selector`. If there are nested uses of `attr` any `:selector` attributes in errors will be updated to reflect the full `selector`. Example: (validate (attr [:name] (present)) {:name "Vlad"})
(chain)
(chain left)
(chain left right)
(chain left right & validations)
Example:
(attr :password (chain (present) (length-over 7))
Example: (attr :password (chain (present) (length-over 7))
Takes an error and returns a human readable version of it.
Takes an error and returns a human readable version of it.
(equals-field first-selector second-selector)
(equals-field first-selector second-selector error-data)
Checks that the values found at each of your selectors are equal to each other
Checks that the values found at each of your selectors are equal to each other
(equals-value value)
(equals-value value error-data)
Checks that the value is equal to the value
that you provide.
Checks that the value is equal to the `value` that you provide.
(guess-field-names errors)
Will convert selectors to strings by swapping hyphens for spaces and capitalising.
Will convert selectors to strings by swapping hyphens for spaces and capitalising.
(join)
(join left)
(join left right)
(join left right & validations)
Example:
(join (attr :name (present)) (attr :age (present)))
Example: (join (attr :name (present)) (attr :age (present)))
(length-in lower upper)
(length-in lower upper error-data)
Checks that the count
of the value is over lower
and under upper
. No
checking is done that lower
is lower than upper
. This validator may
return multiple errors
Checks that the `count` of the value is over `lower` and under `upper`. No checking is done that `lower` is lower than `upper`. This validator may return multiple errors
(length-over size)
(length-over size error-data)
Checks that the count
of the value is over size
.
Checks that the `count` of the value is over `size`.
(length-under size)
(length-under size error-data)
Checks that the count
of the value is under size
.
Checks that the `count` of the value is under `size`.
(matches pattern)
(matches pattern error-data)
Checks that the value is a regex match for pattern
. This uses clojure's
re-matches
function which may not behave as you expect. Your pattern will
have to match the whole string to count as a match.
Checks that the value is a regex match for `pattern`. This uses clojure's `re-matches` function which may not behave as you expect. Your pattern will have to match the whole string to count as a match.
(not-of set)
(not-of set error-data)
Checks that the value is not found within set
Checks that the value is not found within `set`
(one-of set)
(one-of set error-data)
Checks that the value is found within set
Checks that the value is found within `set`
(predicate pred information)
(predicate selector pred information)
Examples: (predicate #(> size (count %)) {:type ::length-over :size size})
(predicate [:user :password] #(> size (count %)) {:type ::length-over :size size})
Examples: (predicate #(> size (count %)) {:type ::length-over :size size}) (predicate [:user :password] #(> size (count %)) {:type ::length-over :size size})
(translate-errors errors translation)
Translates a sequence of errors into a map of plain english error messages. Selectors are used as keys. The error message may be overwritten by setting the :message key in your error map.
Example:
(translate-errors [{ :type :vlad.core/length-under :selector [:password] :name "Password" :size 8}]) ; => {[:password] "Password must be under 8 characters long."}
Translates a sequence of errors into a map of plain english error messages. Selectors are used as keys. The error message may be overwritten by setting the :message key in your error map. Example: (translate-errors [{ :type :vlad.core/length-under :selector [:password] :name "Password" :size 8}]) ; => {[:password] "Password must be under 8 characters long."}
(valid data)
valid
is a validation that does nothing. It can be safely composed with
other validations. It is used as the identity value for reducers/monoid
functions (Don't panic. You don't need to know what that means to use vlad).
`valid` is a validation that does nothing. It can be safely composed with other validations. It is used as the identity value for reducers/monoid functions (Don't panic. You don't need to know what that means to use vlad).
The core of vlad is the Validation
protocol. It simply requires that your
validation type knows how to run against some data. Implementations of
validate
should return a sequence of errors. An error may be anything but
is generally of the form {:type ::something :some-extra-data 123}
.
The core of vlad is the `Validation` protocol. It simply requires that your validation type knows how to run against some data. Implementations of `validate` should return a sequence of errors. An error may be anything but is generally of the form `{:type ::something :some-extra-data 123}`.
(validate self data)
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close