Function for creation of rule-sets, validating, and using validation results
Function for creation of rule-sets, validating, and using validation results
(constraint-or-condition? x)
Returns true if x is either a function or a vector [fn alternative-message].
Returns true if x is either a function or a vector [fn alternative-message].
(has-errors? validation-results)
Returns true if the validation results contain at least one not-nil message.
Returns true if the validation results contain at least one not-nil message.
(map-data-provider m keyword-or-vector)
Default data provider that uses get or get-in to retrieve data from a map/record.
Default data provider that uses get or get-in to retrieve data from a map/record.
(messages validation-results)
(messages localizer-fn validation-results)
Returns a map {path -> sequence-of-human-readable-strings}. If the localizer-fn is not given the default-localizer is used.
Returns a map {path -> sequence-of-human-readable-strings}. If the localizer-fn is not given the default-localizer is used.
(messages-for path validation-results)
(messages-for localizer-fn path validation-results)
Returns a sequence of human readable strings for the given path. If the localizer-fn is not given the default-localizer is used.
Returns a sequence of human readable strings for the given path. If the localizer-fn is not given the default-localizer is used.
(rule-set & specs)
Creates a rule-set from paths, constraints and conditions.
The general structure of specs
is:
path constraints-and-conditions+
path constraints-and-conditions+
A path points to data. It can either be a key, or a vector containing keys. n paths are grouped by a vector to specify multiple data locations that apply to n-arg constraints.
Examples: :foo Specifies a path to value in {:foo value} [:foo :bar] Specifies 2 paths to values in {:foo value1 :bar value2} [[:foo :bar]] Specifies a single path pointing to value in {:foo {:bar value}} [:foo [:bar :baz :bum]] Specifies 2 paths in {:foo value1 :bar {:baz {:bum value2}}}
Constraints are 1-arg functions that return a string to flag a constraint violation for the given value or nil otherwise.
Conditions are 1-arg predicates returning true or false that stop application of subsequent constraints after returning false.
Example: (rule-set :foo required (min-length 3) [[:bar :baz]] number? (in-range 0 10))
Creates a rule-set from paths, constraints and conditions. The general structure of `specs` is: path constraints-and-conditions+ path constraints-and-conditions+ A path points to data. It can either be a key, or a vector containing keys. n paths are grouped by a vector to specify multiple data locations that apply to n-arg constraints. Examples: :foo Specifies a path to value in {:foo value} [:foo :bar] Specifies 2 paths to values in {:foo value1 :bar value2} [[:foo :bar]] Specifies a single path pointing to value in {:foo {:bar value}} [:foo [:bar :baz :bum]] Specifies 2 paths in {:foo value1 :bar {:baz {:bum value2}}} Constraints are 1-arg functions that return a string to flag a constraint violation for the given value or nil otherwise. Conditions are 1-arg predicates returning true or false that stop application of subsequent constraints after returning false. Example: (rule-set :foo required (min-length 3) [[:bar :baz]] number? (in-range 0 10))
(sub-set rule-set & ps)
Returns the subset of the rule-set that contains only those rules that reference at least one of the paths given in ps.
Returns the subset of the rule-set that contains only those rules that reference at least one of the paths given in ps.
(update old-map new-map)
Takes two validation results (or any map) and recursively updates the first with all values of the second. Existing values of the first are kept.
Takes two validation results (or any map) and recursively updates the first with all values of the second. Existing values of the first are kept.
(validate rule-set data)
(validate data-provider rule-set data)
Creates validation results by applying the constraints of the rule-set to the data. If the data-provider arg is missing the map-data-provider is used.
Creates validation results by applying the constraints of the rule-set to the data. If the data-provider arg is missing the map-data-provider is used.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close