@@ -4,12 +4,12 @@ import { Actions } from '../models/actions';
4
4
import { Rule , UniqueConstraint , CallbackConstraint } from '../models/rule' ;
5
5
import { ValidationError } from '../models/validation' ;
6
6
7
- const onlyUniqueValues = ( data : string [ ] ) => {
8
- return new Set ( data ) . size === data . length ;
7
+ const onlyUniqueValues = ( values : string [ ] ) => {
8
+ return new Set ( values ) . size === values . length ;
9
9
} ;
10
10
11
- const findDuplicates = ( data : string [ ] ) => {
12
- return Array . from ( new Set ( data . filter ( ( item , index ) => data . indexOf ( item ) != index ) ) ) ;
11
+ const getDuplicates = ( values : string [ ] ) => {
12
+ return Array . from ( new Set ( values . filter ( ( item , index ) => values . indexOf ( item ) != index ) ) ) ;
13
13
} ;
14
14
15
15
const validateColumn = < T > ( key : keyof T , data : T [ keyof T ] [ ] , rules ?: Rule [ ] ) : ValidationError < T > [ ] => {
@@ -19,7 +19,7 @@ const validateColumn = <T>(key: keyof T, data: T[keyof T][], rules?: Rule[]): Va
19
19
const values = data . map ( ( d ) => new String ( d ) . toString ( ) ) ;
20
20
rules . forEach ( ( r ) => {
21
21
if ( ( r . constraint as UniqueConstraint ) . unique && ! onlyUniqueValues ( values ) ) {
22
- const duplicates = findDuplicates ( values ) ;
22
+ const duplicates = getDuplicates ( values ) ;
23
23
values . forEach ( ( v , i ) => {
24
24
if ( duplicates . indexOf ( v ) !== - 1 ) {
25
25
errors . push ( { column : key , row : i , message : r . message } ) ;
0 commit comments