1
- /* eslint-disable */
1
+ import { FormControl , InputType , ValidationErrors } from '../models' ;
2
2
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 === '' ;
7
5
8
6
const 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 ] ) ? ) * $ / ;
9
7
const 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 ) ) ) ) $ / ;
10
8
11
- export const required = ( control : FormControl < InputType > ) =>
9
+ export const required = (
10
+ control : FormControl < InputType > ,
11
+ ) : ValidationErrors | null =>
12
12
isEmptyInputValue ( control . value ) ? { required : true } : null ;
13
13
14
- export const min = ( min : number ) => ( control : FormControl < InputType > ) => {
14
+ export const min = ( min : number ) => (
15
+ control : FormControl < InputType > ,
16
+ ) : ValidationErrors | null => {
15
17
if ( isEmptyInputValue ( control . value ) || isEmptyInputValue ( min ) ) {
16
18
return null ; // don't validate empty values to allow optional controls
17
19
}
@@ -22,7 +24,9 @@ export const min = (min: number) => (control: FormControl<InputType>) => {
22
24
: null ;
23
25
} ;
24
26
25
- export const max = ( max : number ) => ( control : FormControl < InputType > ) => {
27
+ export const max = ( max : number ) => (
28
+ control : FormControl < InputType > ,
29
+ ) : ValidationErrors | null => {
26
30
if ( isEmptyInputValue ( control . value ) || isEmptyInputValue ( max ) ) {
27
31
return null ; // don't validate empty values to allow optional controls
28
32
}
@@ -34,14 +38,18 @@ export const max = (max: number) => (control: FormControl<InputType>) => {
34
38
: null ;
35
39
} ;
36
40
37
- export const email = ( control : FormControl < InputType > ) => {
41
+ export const email = (
42
+ control : FormControl < InputType > ,
43
+ ) : ValidationErrors | null => {
38
44
if ( isEmptyInputValue ( control . value ) ) {
39
45
return null ; // don't validate empty values to allow optional controls
40
46
}
41
47
return EMAIL_REGEXP . test ( `${ control . value } ` ) ? null : { email : true } ;
42
48
} ;
43
49
44
- export const url = ( control : FormControl < InputType > ) => {
50
+ export const url = (
51
+ control : FormControl < InputType > ,
52
+ ) : ValidationErrors | null => {
45
53
if ( isEmptyInputValue ( control . value ) ) {
46
54
return null ; // don't validate empty values to allow optional controls
47
55
}
@@ -50,7 +58,7 @@ export const url = (control: FormControl<InputType>) => {
50
58
51
59
export const minLength = ( minLength : number ) => (
52
60
control : FormControl < InputType > ,
53
- ) => {
61
+ ) : ValidationErrors | null => {
54
62
if ( isEmptyInputValue ( control . value ) ) {
55
63
return null ; // don't validate empty values to allow optional controls
56
64
}
@@ -62,14 +70,14 @@ export const minLength = (minLength: number) => (
62
70
63
71
export const maxLength = ( maxLength : number ) => (
64
72
control : FormControl < InputType > ,
65
- ) => {
73
+ ) : ValidationErrors | null => {
66
74
const length = control . value ? `${ control . value } ` . length : 0 ;
67
75
return length > maxLength
68
76
? { maxlength : { requiredLength : maxLength , actualLength : length } }
69
77
: null ;
70
78
} ;
71
79
72
- export const pattern = ( pattern : string ) => {
80
+ export const pattern = ( pattern : string ) : ValidationErrors | null => {
73
81
if ( ! pattern ) return null ;
74
82
let regex : RegExp ;
75
83
let regexStr : string | RegExp ;
0 commit comments