Library to validate variable typing and values during runtime. It is built to be used as an ES6 module.
The library follows the concept that typing or value mismatch is an error, so it throws errors if the validation fails. Here are some example usage:
import validate from './libraries/type-validation/validation';
const value = -1;
try {
validate(value).number().positive();
} catch(errorValidatingValue) {
console.log(errorValidatingValue); // logs "Value is NOT Positive"
}
Validates if value is defined (NOT undefined
)
Validates if the value is undefined
Validates if the value is equal to null
Validates if the value is NOT equal to null
Validates if the value is a function
Validates if the values is a number
Validates if the number
is more than or equal to limit
limit
- the minimum value allowed
Validates if the number
is less than or equal to limit
limit
- the maximum value allowed
Validates if the number
is more than 0 (zero)
Validates if the number
is an integer (no significative decimals)
Validates if the value is a string
Validates if the string
is NOT an empty string
(''
)
Validates if the string
's length is less than or equal to the limit
limit
- the maximum allowed length
Validates if the value is a boolean
Validates if the value is an object
Validates if the value is an array
Validates if the value is an HTMLElement
Validates if the value is in a list of values