npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@comparaonline/validator-collection

v2.6.2

Published

Multipurpose validation library

Downloads

1,906

Readme

@comparaonline/validator-collection

Multipurpose validation library for Typescript

Validators

Pattern Validator

Validates that a string follows a regex pattern:

const validator = new PatternValidator("^[0-9]*$");
validator.isValid("12345"); // true
validator.isValid("1234R"); // false

Number Validators

Greater than

const validator = new GreaterThanValidator(5);
validator.isValid(6); // true
validator.isValid(3); // false

Less than

const validator = new LessThanValidator(3);
validator.isValid(-2); // true
validator.isValid(5); // false

Credit Card Validators

Credit card number

const validator = new CreditCardNumberValidator();
validator.isValid("4556049290199451"); // true
validator.isValid("1234567890123456"); // false

CVV

const validator = new CreditCardCvvValidator();
validator.isValid("618", { creditCardNumber: "4916244676983389" }); // true
validator.isValid("6201", { creditCardNumber: "4916244676983389" }); // false

Expiration

Receives a date string in format YYYYMM

const validator = new CreditCardExpirationValidator();
validator.isValid("205001"); // true
validator.isValid("200004"); // false

Date Validators

Date format validator

const validator = new DateFormatValidator("YYYY-MM-DD");
validator.isValid("1970-12-11"); // true
validator.isValid("1999-00-00"); // false

Before date validator

const validator = new BeforeDateValidator("MM-DD-YYYY", "01-01-2020");
validator.isValid("01-01-2019"); // true
validator.isValid("02-01-2020"); // false

After date validator

const validator = new AfterDateValidator("MM-DD-YYYY", "01-01-2020");
validator.isValid("02-01-2020"); // true
validator.isValid("01-01-2019"); // false

Plate Validators

const chilePlateValidator = PlateValidatorFactory.getValidator("CL");
chilePlateValidator.isValid("wxyz12"); // true
chilePlateValidator.isValid("wxyz12", { plateType: "LightVehicle" }); // true
chilePlateValidator.isValid("AB123", {
  plateType: "Motorcycle",
  includeOldFormat: false,
}); // false

const colombiaPlateValidator = PlateValidatorFactory.getValidator("CO");
colombiaPlateValidator.isValid("AAA-123"); // true
colombiaPlateValidator.isValid("CZR-26D"); // false

const colombiaPlateValidator = PlateValidatorFactory.getValidator("CO");
colombiaPlateValidator.isValid("AAA-12", "motorcycle"); // true
colombiaPlateValidator.isValid("CZR-26D", "motorcycle"); // true
colombiaPlateValidator.isValid("CZR-266", "motorcycle"); // false

const brazilPlateValidator = PlateValidatorFactory.getValidator("BR");
brazilPlateValidator.isValid("LBM-4000"); // true
brazilPlateValidator.isValid("LBM-40000"); // false

Email Validator

const validator = new EmailValidator();
validator.isValid("[email protected]"); // true
validator.isValid("testcompara.com"); // false

Phone validators

const chilePhoneValidator = PhoneValidatorFactory.getValidator("CL");
chilePhoneValidator.isValid("+56912345678"); // true;
chilePhoneValidator.isValid("912345678"); // false;

const colombyPhoneValidator = PhoneValidatorFactory.getValidator("CO");
colombyPhoneValidator.isValid("+573575757571"); // true
colombyPhoneValidator.isValid("+573"); // false

const brazilPhoneValidator = PhoneValidatorFactory.getValidator("BR");
brazilPhoneValidator.isValid("21934561112"); // true
brazilPhoneValidator.isValid("1098762222"); // false

National Id Validators

const chileNationalIdValidator = NationalIdValidatorFactory.getValidator("CL");
chileNationalIdValidator.isValid("11.111.111-1"); // true;
chileNationalIdValidator.isValid("17920701-k-k"); // false;

const colombyNationalIdValidator =
  NationalIdValidatorFactory.getValidator("CO");
colombyNationalIdValidator.isValid("2312345"); // true
colombyNationalIdValidator.isValid(""); // false

const brazilNationalIdValidator = NationalIdValidatorFactory.getValidator("BR");
brazilNationalIdValidator.isValid("816.309.700-00"); // true
brazilNationalIdValidator.isValid("122"); // false
brazilNationalIdValidator.matchesControlDigits("816.309.700-00"); // true
brazilNationalIdValidator.matchesControlDigits("816.309.700-01"); // false
brazilNationalIdValidator.matchesControlDigits("816.309.700.01"); // false
brazilNationalIdValidator.matchesControlDigits("81630970001"); // false

Cep Validator

const cepValidator = new CepValidator(/\b\d{5}-\d{3}\b/);
validator.isValid("87690-766"); // true
validator.isValid("87690-7668"); // false