3.0.0 • Published 3 years ago

@terminus/ui-validators v3.0.0

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

CI/CD Status Codecov MIT License
NPM version Library size

A collection of form validators.

Table of Contents

NOTE: This service is provided as a singleton by defining the providedIn property as root.

Usage

import {
  FormBuilder,
  FormGroup,
} from '@angular/forms';
import { TsValidatorsService } from '@terminus/ui-validators';


@Component({
  ...
})
export class MyComponent {
  // Create a form
  myForm: FormGroup = this.formBuilder.group({
    email: [
      null,
      [
        // Basic validator
        this.validatorsService.email(),
      ],
    ],
    greaterThan: [
      null,
      [
        // Validator with a required argument
        this.validatorsService.greaterThan(10),
      ],
    ],
  });

  constructor(
    private formBuilder: FormBuilder,
    private validatorsService: TsValidatorsService,
  ) {}

}

Available validators

ValidatorPurpose
creditCardA credit card number must be valid
emailAn email address must be valid
domainA domain must be valid
equalToControlA control's value must be equal to another control's value
greaterThanA number must be greater than another value
inCollectionA value must be found in a collection
isInRangeA number must be between two numbers
lessThanA number must be less than another value
lowercaseA value must contain a minimum amount of lowercase characters
maxDateA date must be before a maximum date
minDateA date must be after a minimum date
numbersA value must contain a minimum amount of numbers
passwordA password must meet certain requirements
uppercaseA value must contain a minimum amount of uppercase characters
urlA URL must be valid

Mocking

A mocked version of the service is available for testing as TsValidatorsServiceMock from @terminus/ui-validators/testing.

The mocks consist of Jest mock functions. Based on the class value isValid the validator mock will return an error message or null.

3.0.0

3 years ago

2.0.5

3 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.0

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago