File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,30 @@ const isNumeric = (value: string): boolean => {
12
12
return ! isNaN ( + value ) ;
13
13
}
14
14
15
+ const arraysEqual = ( first : any [ ] , second : any [ ] ) : boolean => {
16
+ if ( first . length !== second . length ) {
17
+ return false ;
18
+ }
19
+
20
+ let i = first . length ;
21
+
22
+ while ( i -- ) {
23
+ const indexInSecond = second . findIndex ( ( entry : any ) => entry === first [ i ] ) ;
24
+
25
+ if ( indexInSecond !== - 1 ) {
26
+ second . splice ( indexInSecond , 1 ) ;
27
+ } else {
28
+ return false ;
29
+ }
30
+
31
+ first . splice ( i , 1 ) ;
32
+ }
33
+
34
+ return first . length === 0 && second . length === 0 ;
35
+ }
36
+
15
37
export {
16
38
capitalize ,
17
- isNumeric
39
+ isNumeric ,
40
+ arraysEqual
18
41
}
Original file line number Diff line number Diff line change
1
+ import {
2
+ getValue ,
3
+ } from '../common/dom' ;
4
+ import { Validator } from '../Validator' ;
5
+ import { arraysEqual } from '../common/utils' ;
6
+
7
+ export default ( validator : Validator ) => ( {
8
+ passed ( elements : HTMLElement [ ] , name : string ) : boolean {
9
+ const values = elements . reduce ( ( prev : string [ ] , element : HTMLElement ) => ( [
10
+ ...prev ,
11
+ ...getValue ( element )
12
+ ] ) , [ ] ) ;
13
+
14
+ const otherValues = validator . refs ( name ) . reduce ( ( prev : string [ ] , element : HTMLElement ) => ( [
15
+ ...prev ,
16
+ ...getValue ( element )
17
+ ] ) , [ ] ) ;
18
+
19
+ return arraysEqual ( values , otherValues ) ;
20
+ } ,
21
+ message ( ) : string {
22
+ return 'minLength' ;
23
+ }
24
+ } ) ;
You can’t perform that action at this time.
0 commit comments