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

@multivers/validators

v0.0.2

Published

A collection of validators for Angular Reactive Forms. This library is dependent on Angular only

Downloads

6

Readme

About The Project

Product Name Screen Shot

There are many great validators available on GitHub, however, I didn't find one that really suit my needs so I created this enhanced one. I want to create a validator that anyone can use to validate their Angular Reactive Forms.

Here's why:

  • Your time should be focused on creating something amazing. A project that solves a problem and helps others
  • You shouldn't be doing the same tasks over and over like creating a validator from scratch
  • You should element DRY principles to the rest of your life :smile:
  • You should be able to validate your forms with ease

Installation

Below is how to install the library and use it in your project.

Install the library

  npm install @multivers/validators
  yarn add @multivers/validators
  pnpm add @multivers/validators
import { MultiversControlValidator } from 'multivers-validators';
import { MultiversGroupValidator } from 'multivers-validators';
 this.formGroup =  new FormGroup({
  //Personal Details
  firstName: new FormControl('', []),
  lastName: new FormControl('', Validators.compose([ MultiversControlValidators.lowerCase, MultiversControlValidators.upperCase])),
  birthDate: new FormControl('', Validators.compose([
    Validators.required,
    MultiversControlValidators.date({min: new Date(1990, 0, 1), max:  new Date(2000, 0, 1)}),
  ]),
  )}, {
  validators: [
    MultiversGroupValidators.notContains('password', ['firstName', 'lastName']),
    MultiversGroupValidators.requiredSome(['firstName', 'lastName'], 1),
    MultiversGroupValidators.dateRange('issueDate', 'expiryDate'),
    MultiversGroupValidators.isDifferent('firstName', 'lastName'),
    MultiversGroupValidators.isEquals('password', 'confirmPassword'),
  ]
});

Usage

Please refer to the Documentation

Available Validator Rules

All validators are written as camelCase functions. The following table lists all available validators and their arguments.

Control Validators

See the Control Validators Documentation

| Control Validator | Description | |------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------| | credit-card | The credit-card validator checks if the input is a valid credit card number. It uses the Luhn algorithm to validate the number. | | date: (min:Date\|null=null, max:Date\|null=null) | The date validator checks if the input is a valid date. It supports both ISO 8601 and non-ISO 8601 formats. | | decimal | The decimal validator checks if the input is a valid decimal number. It allows both integer and fractional numbers. | | equal: (compareControl: AbstractControl) | The equal Validates that the value is equal to the value of the compareControl. | | file-type: (allowedTypes: string[]) | The file validator checks if the input is a valid file object. It can be used to validate file inputs in forms. | | hexadecimalColor:(withHash = true) | The hexadecimalColor validator checks if the input is a valid hexadecimal color. | | integer | The integer validator checks if the input is a valid integer. It does not allow fractional numbers. | | ip-address | The ip-address validator checks if the input is a valid IP address. It supports both IPv4 and IPv6 formats. | | lowercase | The lowercase validator checks if the input is a string that contains only lowercase letters. | | number | The number validator checks if the input is a valid number. It allows both integer and decimal numbers. | | phone | The phone validator checks if the input is a valid phone number. It supports both international and local formats. | | range: (min: number, max: number) | The range validator checks if the input is a number that falls within a specified range. | | unique: existingValues | The unique validator checks if the input is unique within a specified array or set of values. It is useful for checking if a username or email is already taken. | | uppercase | The uppercase validator checks if the input is a string that contains only uppercase letters. | | url | The url validator checks if the input is a valid URL. It supports both http and https protocols. |

Group Validators

See the Group Validators Documentation

| Group Validator | Description | |------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | date-range: (startFieldName: string,endFieldName: string ) | Validator for FormGroup that checks if the start date is before or equal to the end date. Params startFieldName , endFieldName | | is-different: (firstField: string, secondField: string) | Validator for FormGroup that checks if the fiels are different. Params firstField secondField | | is-equal: (firstField: string, secondField: string) | Validator for FormGroup that checks if the fiels are equal. Params firstField secondField | | not-contains: toValidateField: string,fields: string[] | Validator for FormGroup that requires a string representing one of the FormControl's name to verified that it doesn't contains same value of others fields ( passed as second parameters , array of string) | | required-some: (fieldNameList : string[], numberRequired:number=1) | Validator for FormGroup that checks if the list of the field have the number of required, Params fieldNameList, numberRequired |

Roadmap

  • [x] Add Changelog
  • [x] Add back to top links
  • [x] Add a lib for forms controls
  • [x] Add a lib for forms group validators
  • [ ] Add Github pages for documentation
  • [ ] Multi-language Support
    • [ ] French

See the open issues for a full list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE.txt for more information.

Contact

Pierre Nédélec - [email protected]

Project Link: https://github.com/multivers-dev/validators

Acknowledgments