ProtectedisWhether the schema requires a non-null/non-undefined value.
Sets the requirement flag. Must be a boolean.
ProtectedpreprocessorsA list of preprocessors associated with the Builder
ProtectedtypeThe string identifier of the schema type (e.g. 'string', 'number', 'object').
Sets the schema type identifier. Must be a non-empty string.
ProtectedvalidatorsA list of validators associated with the Builder
Adds a preprocessor to a preprocessors list
ProtectedassureEnsures a ValidationErrorMessageProvider is valid.
If provider is undefined, falls back to defaultValue.
Function providers are bound to this for access to schema state.
the provider to validate, or undefined
fallback provider when provider is not supplied
a valid ValidationErrorMessageProvider
Consider Infinity as valid.
Consider NaN value as valid
Clear equals() call.
Clears type set by call to .hasType<T>(), default schema type inference will be used
for schema returned by this call.
Clear isInteger() call.
Clear max() call.
Clear min() call.
Remove all preprocessors for this schema.
Remove all validators for this schema.
ProtectedcreateRestricts number to be equal to value.
OptionalerrorMessage: ValidationErrorMessageProvider<NumberSchemaBuilder<TResult, TRequired>>Custom error message provider.
ProtectedgetResolves a ValidationErrorMessageProvider to a string error message.
Handles both string providers and function providers (sync or async).
the error message provider (string or function)
the value that caused the validation error
the resolved error message string
Set type of schema explicitly. notUsed param is needed only for case when JS is used. E.g. when you
can't call method like schema.hasType<Date>(), so instead you can call schema.hasType(new Date())
with the same result.
Optional_notUsed: TGenerates a serializable object describing the defined schema
Make sure that object is not different kinds of infinity. true by default.
EnsureIsFinite error message provider.
EnsureIsInteger error message provider.
Make sure that object is not NaN. true by default.
EnsureNotNaN error message provider. If not provided, default error message will be used.
If set, restrict object to be equal to a certain value.
EqualsTo error message provider. If not provided, default error message will be used.
Allow only integer values (floating point values will be rejected as invalid)
If set to false, schema will be optional (null or undefined values
will be considered as valid).
Max valid value (if defined).
Max valid value error message provider. If not provided, default error message will be used.
Min valid value (if defined).
Min valid value error message provider. If not provided, default error message will be used.
Array of preprocessor functions
Custom error message provider for the 'is required' validation error.
String id of schema type, e.g. string', numberorobject`.
Array of validator functions
Do not accept Infinity.
OptionalerrorMessage: ValidationErrorMessageProvider<NumberSchemaBuilder<TResult, TRequired>>Custom error message provider.
Use clearIsInteger instead. Float values will be considered as valid after this call.
Only integer values will be considered as valid after this call.
OptionalerrorMessage: ValidationErrorMessageProvider<NumberSchemaBuilder<TResult, TRequired>>Custom error message provider.
Restrict number to be no more than maxValue.
OptionalerrorMessage: ValidationErrorMessageProvider<NumberSchemaBuilder<TResult, TRequired>>Custom error message provider.
Restrict number to be at least minValue.
OptionalerrorMessage: ValidationErrorMessageProvider<NumberSchemaBuilder<TResult, TRequired>>Custom error message provider.
Do not accept NaN value
OptionalerrorMessage: ValidationErrorMessageProvider<NumberSchemaBuilder<TResult, TRequired>>Custom error message provider.
ProtectedpreRuns preprocessors, validators, and the required/optional check on object.
Subclasses call this at the start of their validate() implementation to get
a preprocessed value wrapped in a transaction, along with any early errors.
the value to pre-validate
Optionalcontext: ValidationContext<SchemaBuilder<any, any>>optional validation context settings
a PreValidationResult containing the preprocessed transaction, context, and any errors
Performs validation of number schema over object.
Optionalcontext: ValidationContextOptional ValidationContext settings.
Number schema builder class. Allows to create Number schemas. Can be required or optional, can be restricted to be equal to a certain value, can be restricted to be in a certain range, can be restricted to be integer.
NOTE this class is exported only to give opportunity to extend it by inheriting. It is not recommended to create an instance of this class directly. Use number() function instead.
Example: ```ts const schema = number().equals(42); const result = await schema.validate(42); // result.valid === true // result.object === 42 ```
Example: ```ts const schema = number(); const result = await schema.validate('42'); // result.valid === false // result.errors[0].message === 'is expected to be a number' ```
Example: ```ts const schema = number().min(0).max(100); const result = await schema.validate(42); // result.valid === true // result.object === 42 ```
Example: ```ts const schema = number().min(0).max(100); const result = await schema.validate(142.5); // result.valid === false // result.errors[0].message === 'is expected to be less than or equal to 100' ```
See
number