1.0.0 • Published 3 years ago

@stockvio/validator v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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

  1. Import the validate method from the package
import { validate } from '@stockvio/validator';
  1. 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() Returns true if and only if all the other methods - but isBlank - return true

  • Password validate.password(string)

    • .minLen() Same as is name.minLen

    • .maxLen() Same as is name.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() Returns true if and only if all the other methods return true

  • 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 length
    • MAX_LENGTH Maximum length
  • Password config.password
    • MIN_LENGTH Minimum length
    • MAX_LENGTH Maximum length
    • MIN_UPPER Minimum amount of upper case letters, accented or not
    • MIN_NUMBER Maximum amount of numbers
    • MIN_SPECIAL Minimum amount of special characters
1.0.0

3 years ago