1+ import { isArray } from './isArray'
12import { isPlainObject } from './isPlainObject'
3+ import { isReg } from './isReg'
24
35// 深比较
4- export function deepCompare ( comp1 : any , comp2 : any , error : string [ ] = [ ] , errorMsg : string [ ] = [ ] , name ?: string , index ?: string ) {
6+ export function deepCompare ( comp1 : any , comp2 : any , ignoreKeys ?: string [ ] | RegExp , error : string [ ] = [ ] , errorMsg : string [ ] = [ ] , name ?: string , index ?: string ) {
57 if ( isPlainObject ( comp1 ) && isPlainObject ( comp2 ) ) {
68 const longer = Object . keys ( comp1 ) . length >= Object . keys ( comp2 ) . length
79 ? comp1
810 : comp2
911 for ( const key in longer ) {
12+ if ( ( isArray ( ignoreKeys ) && ( ignoreKeys as string [ ] ) . includes ( key ) ) || ( isReg ( ignoreKeys ) && ( ignoreKeys as RegExp ) . test ( key ) ) )
13+ continue
14+
1015 const value1 = comp1 [ key ]
1116 const value2 = comp2 [ key ]
1217 const _key = name ? `${ name } .${ key } ` : key
13- deepCompare ( value1 , value2 , error , errorMsg , _key )
18+ deepCompare ( value1 , value2 , ignoreKeys , error , errorMsg , _key )
1419 }
1520 }
1621 else if ( Array . isArray ( comp1 ) && Array . isArray ( comp2 ) ) {
@@ -20,7 +25,7 @@ export function deepCompare(comp1: any, comp2: any, error: string[] = [], errorM
2025 for ( const key in longer ) {
2126 const value1 = comp1 [ key ]
2227 const value2 = comp2 [ key ]
23- deepCompare ( value1 , value2 , error , errorMsg , name , key )
28+ deepCompare ( value1 , value2 , ignoreKeys , error , errorMsg , name , key )
2429 }
2530 }
2631 else if ( comp1 !== comp2 ) {
0 commit comments