@stockvio/validator v1.0.0
Validator
Input validation methods used in Stockvio's systems
At the moment, it's not possible to change the configuration that define whether something is or is not valid. We plan to add this in a future update but, at the moment, this package is built to satisfy Stockvio's needs exclusively
Usage
- Import the
validate
method from the package
import { validate } from '@stockvio/validator';
- Use it as needed
validate.name("Lorem Ipsum").all(); // true
validate.password("weak-passWord").all(); // false
validate.email("not@email"); // false
validate.cpf("522.512.330-91"); // true
Documentation
Although the code is fully documented using Typescript declarations - you should be able to get a hang of the package only by reading the intellisense documentation - here's a quick reference of the API:
validate
Validation methods
Name
validate.name(string)
.minLen()
Returns if the length of the provided string, after trimming it, is greater than or equal to the minimum length.maxLen()
Returns if the length of the provided string, after trimming it, it less or equal to the maximum length.onlyLettersAndSpaces()
Returns if the provided string contains only letters - accented or not - and spaces.noDoubleSpaces()
Returns if the provided string does not contain consecutive spaces.isBlank()
Returns if the provided string is empty or contains only spaces.all()
Returnstrue
if and only if all the other methods - butisBlank
- returntrue
Password
validate.password(string)
.minLen()
Same as isname.minLen
.maxLen()
Same as isname.maxLen
.lowerCase()
Returns if the provided string contains the minimum amount of lower case letters, accented or not.upperCase()
Returns if the provided string contains the minimum amount of upper case letters, accented or not.number()
Returns if the provided string contains the minimum amount of digits.specialChar()
Returns if the provided string contains the minimum amount of special characters.all()
Returnstrue
if and only if all the other methods returntrue
Email
- Returns if the provided string is, likely, a validity email address
CPF
- Returns if the provided string if, after disconsidering all non-numeric characters, a valid brazilian CPF number
config
Parameters used to define if something is valid or not. Since, at the moment, these values are not configurable, check them here.
- Name
config.name
MIN_LENGTH
Minimum lengthMAX_LENGTH
Maximum length
- Password
config.password
MIN_LENGTH
Minimum lengthMAX_LENGTH
Maximum lengthMIN_UPPER
Minimum amount of upper case letters, accented or notMIN_NUMBER
Maximum amount of numbersMIN_SPECIAL
Minimum amount of special characters
3 years ago