Abstract
the type of the value
Protected
constructorthe application configuration
the validator configuration
the name of the value
the value being validated
the contextual information set by a parent validator or the user
the list of validation failures
Protected
Readonly
_The validator configuration.
Protected
Readonly
contextThe contextual information of this validator.
Protected
Readonly
failuresThe list of validation failures.
Protected
Readonly
nameThe name of the value.
Protected
Readonly
scopeThe application configuration.
Readonly
valueThe value being validated.
Adds a validation failure and throws an error if the validator is configured to throw an error on failure.
a message that explains what went wrong
creates the error associated with this failure
Protected
addAdds a RangeError
validation failure and throws an error if the validator is configured
to throw an error on failure.
a message that explains what went wrong
Adds a TypeError
validation failure and throws an error if the validator is
configured to throw an error on failure.
a message that explains what went wrong
Facilitates the validation of related properties. For example,
```ts requireThat(nameToFrequency, "nameToFrequency"). and(m => m.size().isPositive()). and(m => m.keySet().contains("John")); ```
Any changes made during the validation process will impact this validator.
the nested validation
this
Throws an error if a validation failed; otherwise, returns true
.
true if the validation passed
Protected
failFails the validation if the value is undefined
or null
.
Returns the contextual information for upcoming validations carried out by this validator. The contextual
information is a map of key-value pairs that can provide more details about validation failures. For
example, if the message is "Password may not be empty" and the map contains the key-value pair
{"username": "john.smith"}
, the error message would be:
Password may not be empty
username: john.smith
an unmodifiable map from each entry's name to its value
Returns the contextual information associated with this validator.
the contextual information associated with this validator
Returns the name of the value.
the name of the value
the string to prepend to the name if the name is null
the name of the value
the string to prepend to the value if the name is null
a value
the prefixed name if it is defined; otherwise, the prefixed string representation of the value
the application configuration
Ensures that the value is equal to expected
.
the expected value
this
Ensures that the value is an instance of a class.
the desired class
the desired class
a validator for an object of the desired class
Ensures that the value is not equal to unwanted
.
the unwanted value
this
Ensures that the value is not an instance of a class.
this
Ensures that the value is not null
.
This method should be used to validate method arguments that are assigned to class fields but not accessed right away (such as constructor and setter arguments). It should also be used to validate any method arguments when the validator contains additional contextual information.
this
Ensures that the value is not undefined.
This method should be used to validate method arguments that are assigned to class fields but not accessed right away (such as constructor and setter arguments). It should also be used to validate any method arguments when the validator contains additional contextual information.
this
Ensures that the value has the specified type.
the expected type of the value
this
Protected
requireEnsures that a name does not conflict with other variable names already in use by the validator.
the name of the parameter
false
to allow the name to be used even if it conflicts with an
existing name in the validator context
the internal validator of the name
Checks if any validation has failed.
true
if at least one validation has failed
Sets the contextual information for upcoming validations.
This method adds contextual information to error messages. The contextual information is stored as key-value pairs in a map. Values set by this method override any values that are set using Validators.withContext.
There is no way to remove contextual information from a validator. Thread-level contextual information is removed automatically.
the value of the entry
the name of an entry
this
Protected
Static
Readonly
VALUE_
Validates the state of a value, recording failures without throwing an error.