1- /* eslint-disable */
1+ import { FormControl , InputType , ValidationErrors } from '../models' ;
22
3- import { FormControl , InputType } from '../models' ;
4-
5- export const isEmptyInputValue = ( value : any ) =>
6- value == null || value === '' || value . length === 0 ;
3+ export const isEmptyInputValue = ( value : string | number | boolean ) : boolean =>
4+ value == null || value === '' ;
75
86const EMAIL_REGEXP = / ^ (? = .{ 1 , 254 } $ ) (? = .{ 1 , 64 } @ ) [ - ! # $ % & ' * + / 0 - 9 = ? A - Z ^ _ ` a - z { | } ~ ] + ( \. [ - ! # $ % & ' * + / 0 - 9 = ? A - Z ^ _ ` a - z { | } ~ ] + ) * @ [ A - Z a - z 0 - 9 ] ( [ A - Z a - z 0 - 9 - ] { 0 , 61 } [ A - Z a - z 0 - 9 ] ) ? ( \. [ A - Z a - z 0 - 9 ] ( [ A - Z a - z 0 - 9 - ] { 0 , 61 } [ A - Z a - z 0 - 9 ] ) ? ) * $ / ;
97const URL_REGEXP = / ^ ( (?: ( h t t p s ? ) : \/ \/ ) ? ( (?: 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | 1 [ 0 - 9 ] [ 0 - 9 ] | [ 0 - 9 ] [ 0 - 9 ] | [ 0 - 9 ] ) \. (?: (?: 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | 1 [ 0 - 9 ] [ 0 - 9 ] | [ 0 - 9 ] [ 0 - 9 ] | [ 0 - 9 ] ) \. ) (?: (?: 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | 1 [ 0 - 9 ] [ 0 - 9 ] | [ 0 - 9 ] [ 0 - 9 ] | [ 0 - 9 ] ) \. ) (?: (?: 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | 1 [ 0 - 9 ] [ 0 - 9 ] | [ 0 - 9 ] [ 0 - 9 ] | [ 0 - 9 ] ) ) | (?: (?: (?: \w + \. ) { 1 , 2 } [ \w ] { 2 , 3 } ) ) ) (?: : ( \d + ) ) ? ( (?: \/ [ \w ] + ) * ) (?: \/ | ( \/ [ \w ] + \. [ \w ] { 3 , 4 } ) | ( \? (?: ( [ \w ] + = [ \w ] + ) & ) * ( [ \w ] + = [ \w ] + ) ) ? | \? (?: ( w s d l | w a d l ) ) ) ) $ / ;
108
11- export const required = ( control : FormControl < InputType > ) =>
9+ export const required = (
10+ control : FormControl < InputType > ,
11+ ) : ValidationErrors | null =>
1212 isEmptyInputValue ( control . value ) ? { required : true } : null ;
1313
14- export const min = ( min : number ) => ( control : FormControl < InputType > ) => {
14+ export const min = ( min : number ) => (
15+ control : FormControl < InputType > ,
16+ ) : ValidationErrors | null => {
1517 if ( isEmptyInputValue ( control . value ) || isEmptyInputValue ( min ) ) {
1618 return null ; // don't validate empty values to allow optional controls
1719 }
@@ -22,7 +24,9 @@ export const min = (min: number) => (control: FormControl<InputType>) => {
2224 : null ;
2325} ;
2426
25- export const max = ( max : number ) => ( control : FormControl < InputType > ) => {
27+ export const max = ( max : number ) => (
28+ control : FormControl < InputType > ,
29+ ) : ValidationErrors | null => {
2630 if ( isEmptyInputValue ( control . value ) || isEmptyInputValue ( max ) ) {
2731 return null ; // don't validate empty values to allow optional controls
2832 }
@@ -34,14 +38,18 @@ export const max = (max: number) => (control: FormControl<InputType>) => {
3438 : null ;
3539} ;
3640
37- export const email = ( control : FormControl < InputType > ) => {
41+ export const email = (
42+ control : FormControl < InputType > ,
43+ ) : ValidationErrors | null => {
3844 if ( isEmptyInputValue ( control . value ) ) {
3945 return null ; // don't validate empty values to allow optional controls
4046 }
4147 return EMAIL_REGEXP . test ( `${ control . value } ` ) ? null : { email : true } ;
4248} ;
4349
44- export const url = ( control : FormControl < InputType > ) => {
50+ export const url = (
51+ control : FormControl < InputType > ,
52+ ) : ValidationErrors | null => {
4553 if ( isEmptyInputValue ( control . value ) ) {
4654 return null ; // don't validate empty values to allow optional controls
4755 }
@@ -50,7 +58,7 @@ export const url = (control: FormControl<InputType>) => {
5058
5159export const minLength = ( minLength : number ) => (
5260 control : FormControl < InputType > ,
53- ) => {
61+ ) : ValidationErrors | null => {
5462 if ( isEmptyInputValue ( control . value ) ) {
5563 return null ; // don't validate empty values to allow optional controls
5664 }
@@ -62,14 +70,14 @@ export const minLength = (minLength: number) => (
6270
6371export const maxLength = ( maxLength : number ) => (
6472 control : FormControl < InputType > ,
65- ) => {
73+ ) : ValidationErrors | null => {
6674 const length = control . value ? `${ control . value } ` . length : 0 ;
6775 return length > maxLength
6876 ? { maxlength : { requiredLength : maxLength , actualLength : length } }
6977 : null ;
7078} ;
7179
72- export const pattern = ( pattern : string ) => {
80+ export const pattern = ( pattern : string ) : ValidationErrors | null => {
7381 if ( ! pattern ) return null ;
7482 let regex : RegExp ;
7583 let regexStr : string | RegExp ;
0 commit comments