@@ -133,32 +133,30 @@ export function convertToRows(columns: Array<_Column>): Array<Array<_Column>> {
133133 return rows ;
134134}
135135
136- const isObject = ( obj : Object ) : boolean => {
137- return Object . prototype . toString . call ( obj ) === '[object Object]'
138- }
139- const isArray = ( arr : number ) : boolean => {
140- return Object . prototype . toString . call ( arr ) === '[object Array]'
141- }
136+ const checkType = ( data : any ) : string => Object . prototype . toString . call ( data ) . toLowerCase ( ) . slice ( 8 , - 1 ) ;
137+
142138const deepCompare = ( obj1 : any , obj2 : any ) : boolean => {
143- if ( obj1 && obj2 && obj1 . length !== obj2 . length ) {
144- return true
145- } else if ( isArray ( obj1 ) && isArray ( obj2 ) ) {
146- return obj1 . some ( ( value , key ) => (
147- deepCompare ( value , obj2 [ key ] )
148- ) )
149- } else if ( isObject ( obj1 ) && isObject ( obj2 ) ) {
150- for ( let key in obj1 ) {
151- if ( deepCompare ( obj1 [ key ] , obj2 [ key ] ) ) {
152- return true
153- }
139+ const obj1Type = checkType ( obj1 ) ;
140+ const obj2Type = checkType ( obj2 ) ;
141+ if ( obj1Type !== obj2Type ) return false ;
142+
143+ if ( obj1Type === 'array' && obj1 . length === obj2 . length ) {
144+ return obj1 . every ( ( value , key ) => (
145+ deepCompare ( value , obj2 [ key ] )
146+ ) )
147+ }
148+
149+ if ( obj1Type === 'object' ) {
150+ for ( let key in obj1 ) {
151+ if ( ! Object . keys ( obj2 ) . includes ( key ) ) return false ;
152+ return deepCompare ( obj1 [ key ] , obj2 [ key ] )
153+ }
154+ return false
154155 }
155- return false
156- }
157- return obj1 !== obj2
156+ return Object . is ( obj1 , obj2 ) ;
158157}
159158
160159export {
161160 deepCompare ,
162- isObject ,
163- isArray
161+ checkType ,
164162}
0 commit comments