Patterns for some maps passed to the functions as arguments:
key | value | description | mandatory extra key | optional extra key |
---|---|---|---|---|
:validate/type | :validate/mandatory | validates if field is present | - | :validate/message ^string with %s being field name |
:validate/type | :validate/max | validates if max is not reached | :validate/value ˆint | :validate/message ^string with 1st %s being field name, 2nd being max value :validate/ignore-if-absent ^boolean to ignore validation for absent field |
:validate/type | :validate/min | validates if at least min value is reached | :validate/value ˆint | :validate/message ^string with 1st %s being field name, 2nd being min value :validate/ignore-if-absent ^boolean to ignore validation for absent field |
:validate/type | :validate/regex | validates if string matches regex pattern | :validate/value ˆregex | :validate/message ^string with %s being field name :validate/ignore-if-absent ^boolean to ignore validation for absent field |
:validate/type | :validate/custom | validates if custom fn receiving the value returns true | :validate/value ^fn | :validate/message ^string with %s being field name |
{"field-name"
[{:validate/type :validate/mandatory, :validate/message "%s is ..."},
{:validate/type :validate/min, :validate/value 12, :validate/message "%s is mandatory"},
{:validate/type :validate/max, :validate/value 40, :validate/message "%s is ..."},
{:validate/type :validate/regex, :validate/value #"^[\d]{1,2}$", :validate/message "%s is ..."},
{:validate/type :validate/custom, :validate/value fn, :validate/message "% is ..."}]}
key | value / default | description |
---|---|---|
:ignore-uuid | boolean / false | ignores string to uuid conversion, making the algorithm a bit faster |
{:ignore-uuid true}
(extract-field-value :name {:name "Rosa"})
;=> "Rosa"
(extract-field-value :id {:id "53bd29d3-9b41-4550-83cc-f970d49da04d"})
;=> #uuid "53bd29d3-9b41-4550-83cc-f970d49da04d"
(is-uuid "53bd29d3-9b41-4550-83cc-f970d49da04d") ;=> true
(mop-fields {:name "Rosa" :age 41} ["name"])
;=> {:name "Rosa"}
(uuid) ;=> #uuid "53bd29d3-9b41-4550-83cc-f970d49da04d"
(uuid-as-string (uuid)) ;=> "53bd29d3-9b41-4550-83cc-f970d49da04d"
(validate-and-mop!! {:name "Rosa" :extra 6} ["name"] ["name"])
;=> {:name "Rosa"}
(validate-and-mop!! {:name "Rosa"} ["age"] ["name" "age"])
;=> ExceptionInfo thrown => ExceptionInfo{data {:type :bad-format
; :validation-messages [{:field "age"
; :message "Field :age is not present"}]}}
(validate-and-mop!!
{:name "Rosa" :age 17}
{"age" [{:validate/type :validate/min, :validate/value 18}]}
["name" "age"])
;=> ExceptionInfo thrown => ExceptionInfo{data {:type :bad-format
; :validation-messages [{:field "age"
; :message "Field age must have a minimum size of 18"}]}}
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close