Additional validators for Struct library. It DOES NOT include Struct itself.
[struct.validators "0.9.0"]
This library adds following validators:
non-blank
: forces a non-nil value not to be blank (spaces aren't allowed)non-blank-like
: coerces a non-nil value tonil
if the value is an empty string or contains only white spaces coerces the value tonil
, otherwise makes no changeskeyword-like
: coerces a non-blank value to akeyword
truth
: validates if a given value istrue
enum-factory
: creates a validator that validates if a value is in a given coll (it should be a set for perf.)every-factory
: creates a validator that validates if all items in a sequence satisfy a given scheme, allow to pass an option map forvalidate
function ({:strip true}
is used as default)bigdec-str
: coerces a non-blank value to abigdec
(Clojure only)uuid-str-like
: works like the originaluuid-str
, but accepts also future version of UUIDcz-phone
: validates a given value if it's a valid phone number, if so it formats the value intoE164
(+420777666555), if the value is without prefix,+420
will be used as default (Clojure only)
Validators for other countries can be defined via phone-factory
function e.g.:
(require '[structs.api :as st])
(def de-phone (st/phone-factory "DE"))
Consider using namespace struct.api
that combines all public functions and validators from struct.core
and struct.validators
at one place. Example:
(require '[struct.api :as st])
(st/validate {:name "foo"} {:name [st/required st/non-blank]})
[nil {:name "foo"}]