(assert pred?)
(assert pred? opts)
Validates if a value satisfies a predicate function.
Arguments:
Options:
Returns a validator function that accepts a context and returns a result with the original value if the predicate returns true.
Validates if a value satisfies a predicate function. Arguments: - pred? - A predicate function that returns true for valid values Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with the original value if the predicate returns true.
(boolean)
(boolean opts)
Validates if a value is a boolean.
Options:
Returns a validator function that accepts a context and returns a result.
Validates if a value is a boolean. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result.
(chain & validators)
Creates a validator that applies multiple validators in sequence.
Arguments:
Returns a validator function that accepts a context and returns a result. Each validator is applied to the result of the previous validator. If any validator fails, the chain stops and returns the error.
Creates a validator that applies multiple validators in sequence. Arguments: - validators - A sequence of validator functions to apply in order Returns a validator function that accepts a context and returns a result. Each validator is applied to the result of the previous validator. If any validator fails, the chain stops and returns the error.
(date & [opts])
Validates if a value is a valid JavaScript Date object.
Options:
Returns a validator function that accepts a context and returns a result with the original Date object if valid.
Validates if a value is a valid JavaScript Date object. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with the original Date object if valid.
(date->number)
(date->number opts)
Converts a JavaScript Date object to a timestamp number.
Options:
Returns a validator function that accepts a context and returns a result with the timestamp (milliseconds since epoch) of the date.
Converts a JavaScript Date object to a timestamp number. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with the timestamp (milliseconds since epoch) of the date.
(date->string)
(date->string opts)
Converts a JavaScript Date object to an ISO string.
Options:
Returns a validator function that accepts a context and returns a result with the ISO string representation of the date.
Converts a JavaScript Date object to an ISO string. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with the ISO string representation of the date.
(default validator default-value-or-fn)
Creates a validator that provides a default value for nil inputs.
Arguments:
Returns a validator function that accepts a context and returns a result. If the input is nil, returns the default value or the result of calling the default function with the context.
Creates a validator that provides a default value for nil inputs. Arguments: - validator - A validator function to apply to non-nil values - default-value-or-fn - A value or function to use as default for nil values Returns a validator function that accepts a context and returns a result. If the input is nil, returns the default value or the result of calling the default function with the context.
(enum kws)
(enum kws opts)
Validates if a value is one of a set of keywords.
Arguments:
Options:
Returns a validator function that accepts a context and returns a result with the original keyword if it's one of the specified enum values.
Validates if a value is one of a set of keywords. Arguments: - kws - A collection of keywords representing valid enum values Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with the original keyword if it's one of the specified enum values.
(error message)
Creates an error result with the given message.
Returns a vector with :v/error status and the error message.
Creates an error result with the given message. Returns a vector with :v/error status and the error message.
(errors errors)
Creates a result containing multiple errors.
Returns a vector with :v/errors status and a collection of error messages.
Creates a result containing multiple errors. Returns a vector with :v/errors status and a collection of error messages.
(fail & {:keys [input errors]})
Creates a failed validation result.
Returns a map with :v/fail status, the input value, and error messages.
Creates a failed validation result. Returns a map with :v/fail status, the input value, and error messages.
(hash-map value-validator)
(hash-map key-validator value-validator)
(hash-map key-validator value-validator opts)
Validates if a value is a hash-map with a key and value type.
Arguments:
Options:
Returns a validator function that accepts a context and returns a result with a hash-map of unknown size.
Validates if a value is a hash-map with a key and value type. Arguments: - key - A key validator function - value - A value validator function Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with a hash-map of unknown size.
(instance class-fn)
(instance class-fn opts)
Validates if a value is an instance of a specific class.
Arguments:
Options:
Returns a validator function that accepts a context and returns a result with the original value if it's an instance of the specified class.
Validates if a value is an instance of a specific class. Arguments: - class-fn - A JavaScript constructor function or class Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with the original value if it's an instance of the specified class.
(keyword)
(keyword opts)
Validates if a value is a keyword.
Options:
Returns a validator function that accepts a context and returns a result.
Validates if a value is a keyword. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result.
(lazy validator-fn & [opts])
Creates a validator that lazily evaluates a validator function.
Arguments:
Options:
Returns a validator function that accepts a context and returns a result. The validator-fn is called to get the actual validator only when needed, which allows for recursive validator definitions.
Creates a validator that lazily evaluates a validator function. Arguments: - validator-fn - A function that returns a validator function Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result. The validator-fn is called to get the actual validator only when needed, which allows for recursive validator definitions.
(list validator & [opts])
Validates if a value is a list and validates each element.
Arguments:
Options:
Returns a validator function that accepts a context and returns a result with a sequence of validated elements if successful.
Validates if a value is a list and validates each element. Arguments: - validator - A validator function to apply to each element Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with a sequence of validated elements if successful.
(list-tuple validators & [opts])
Validates if a value is a list with specific validators for each position.
Arguments:
Options:
Returns a validator function that accepts a context and returns a result with a sequence of validated elements if successful. The input list must have the same length as the validators sequence.
Validates if a value is a list with specific validators for each position. Arguments: - validators - A sequence of validator functions, one for each position Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with a sequence of validated elements if successful. The input list must have the same length as the validators sequence.
(literal expected)
(literal expected opts)
Validates if a value equals an expected literal value.
Arguments:
Options:
Returns a validator function that accepts a context and returns a result with the original value if it equals the expected value.
Validates if a value equals an expected literal value. Arguments: - expected - The exact value to match against Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with the original value if it equals the expected value.
(nil-value)
(nil-value opts)
Validates if a value is nil.
Options:
Returns a validator function that accepts a context and returns a result.
Validates if a value is nil. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result.
(nilable validator)
Creates a validator that allows nil values or validates non-nil values.
Arguments:
Returns a validator function that accepts a context and returns a result with nil for nil values or the result of applying the validator to non-nil values.
Creates a validator that allows nil values or validates non-nil values. Arguments: - validator - A validator function to apply to non-nil values Returns a validator function that accepts a context and returns a result with nil for nil values or the result of applying the validator to non-nil values.
(number)
(number opts)
Validates if a value is a number.
Options:
Returns a validator function that accepts a context and returns a result.
Validates if a value is a number. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result.
(number->date)
(number->date opts)
Converts a number (timestamp) to a JavaScript Date object.
Options:
Returns a validator function that accepts a context and returns a result with a Date object if the number represents a valid timestamp.
Converts a number (timestamp) to a JavaScript Date object. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with a Date object if the number represents a valid timestamp.
(numeric)
(numeric opts)
Validates if a value can be parsed as a number.
Options:
Returns a validator function that accepts a context and returns a result. The original string value is returned if valid.
Validates if a value can be parsed as a number. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result. The original string value is returned if valid.
(ok value)
Creates a success result with the given value.
Returns a vector with :v/ok status and the value.
Creates a success result with the given value. Returns a vector with :v/ok status and the value.
(ok? [status _value])
Checks if a result is successful.
Returns true if the result has :v/ok status, false otherwise.
Checks if a result is successful. Returns true if the result has :v/ok status, false otherwise.
(pass & {:keys [input output]})
Creates a successful validation result.
Returns a map with :v/pass status and the input and output values.
Creates a successful validation result. Returns a map with :v/pass status and the input and output values.
(record validators-map & [opts])
Validates if a value is a hash-map and validates specific keys.
Arguments:
Options:
Returns a validator function that accepts a context and returns a result with a map of validated key-value pairs if successful.
Validates if a value is a hash-map and validates specific keys. Arguments: - validators-map - A hash-map of keys to validator functions Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with a map of validated key-value pairs if successful.
(regex regex-str)
(regex regex-str opts)
Validates if a string matches a regular expression pattern.
Arguments:
Options:
Returns a validator function that accepts a context and returns a result with the original string if it matches the pattern.
Validates if a string matches a regular expression pattern. Arguments: - regex-str - The regular expression pattern as a string Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with the original string if it matches the pattern.
(result-case [status val-or-msg]
&
{:keys [ok err errs] :or {ok identity err identity errs identity}})
Pattern matches on a validation result and applies the appropriate handler function.
Takes a result vector [status value] and handler functions for each possible status. Returns the result of applying the matching handler to the value.
Pattern matches on a validation result and applies the appropriate handler function. Takes a result vector [status value] and handler functions for each possible status. Returns the result of applying the matching handler to the value.
(set validator & [opts])
Validates if a value is a set and validates each element.
Arguments:
Options:
Returns a validator function that accepts a context and returns a result with a set of validated elements if successful.
Validates if a value is a set and validates each element. Arguments: - validator - A validator function to apply to each element Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with a set of validated elements if successful.
(string)
(string opts)
Validates if a value is a string.
Options:
Returns a validator function that accepts a context and returns a result.
Validates if a value is a string. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result.
(string->boolean)
(string->boolean opts)
Converts a string ('true' or 'false') to a boolean.
Options:
Returns a validator function that accepts a context and returns a result with the parsed boolean value if successful.
Converts a string ('true' or 'false') to a boolean. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with the parsed boolean value if successful.
(string->date)
(string->date opts)
Converts a string to a JavaScript Date object.
Options:
Returns a validator function that accepts a context and returns a result with a Date object if the string can be parsed as a valid date.
Converts a string to a JavaScript Date object. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with a Date object if the string can be parsed as a valid date.
(string->keyword)
(string->keyword opts)
Converts a string to a keyword.
Options:
Returns a validator function that accepts a context and returns a result with the converted keyword if successful. The string must match the pattern for valid keywords (optionally starting with ':' followed by valid characters).
Converts a string to a keyword. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with the converted keyword if successful. The string must match the pattern for valid keywords (optionally starting with ':' followed by valid characters).
(string->number)
(string->number opts)
Converts a string to a number.
Options:
Returns a validator function that accepts a context and returns a result with the parsed number value if successful.
Converts a string to a number. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with the parsed number value if successful.
(string->symbol)
(string->symbol opts)
Converts a string to a symbol.
Options:
Returns a validator function that accepts a context and returns a result with the converted symbol if successful. The string must match the pattern for valid symbols (starting with a letter followed by valid characters).
Converts a string to a symbol. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with the converted symbol if successful. The string must match the pattern for valid symbols (starting with a letter followed by valid characters).
(symbol)
(symbol opts)
Validates if a value is a symbol.
Options:
Returns a validator function that accepts a context and returns a result.
Validates if a value is a symbol. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result.
(union & validators)
Creates a validator that tries multiple validators and succeeds if any one succeeds.
Arguments:
Returns a validator function that accepts a context and returns a result. Each validator is tried in order until one succeeds. If all validators fail, returns the errors from the last validator.
Creates a validator that tries multiple validators and succeeds if any one succeeds. Arguments: - validators - A sequence of validator functions to try Returns a validator function that accepts a context and returns a result. Each validator is tried in order until one succeeds. If all validators fail, returns the errors from the last validator.
(uuid)
(uuid opts)
Validates if a string is a valid UUID.
Options:
Returns a validator function that accepts a context and returns a result with the original UUID string if valid.
Validates if a string is a valid UUID. Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with the original UUID string if valid.
(valid? result)
Checks if a validation result is successful.
Returns true if the result has :v/pass status, false otherwise.
Checks if a validation result is successful. Returns true if the result has :v/pass status, false otherwise.
(validate validator-fn input & [opts])
Validates an input value using the provided validator function.
Creates a validation context with the input, applies the validator, and returns a validation result map (pass or fail).
Validates an input value using the provided validator function. Creates a validation context with the input, applies the validator, and returns a validation result map (pass or fail).
(vector validator & [opts])
Applies a validator to every item in a vector
Arguments:
Options:
Returns a validator function that accepts a context and returns a result with a vector of validated elements if successful.
Applies a validator to every item in a vector Arguments: - validator - A validator function to apply to each element Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with a vector of validated elements if successful.
(vector-tuple validators & [opts])
Validates if a value is a vector with specific validators for each position.
Arguments:
Options:
Returns a validator function that accepts a context and returns a result with a vector of validated elements if successful. The input vector must have the same length as the validators vector.
Validates if a value is a vector with specific validators for each position. Arguments: - validators - A vector of validator functions, one for each position Options: - :message - Custom error message function or string Returns a validator function that accepts a context and returns a result with a vector of validated elements if successful. The input vector must have the same length as the validators vector.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close