@@ -17,10 +17,12 @@ const EMPTY_VALUES = [
1717
1818const DEFAULT_OPTIONS = {
1919 emptyValues : EMPTY_VALUES ,
20- ignoreHtml : true
20+ ignoreHtml : true ,
21+ ignoreWhitespace : true
2122} ;
2223
2324const HTML_REGEX = / ( < ( [ ^ > ] + ) > ) / gi;
25+ const WHITESPACE_REGEX = / \s \s + / g;
2426
2527/**
2628 * Returns true if the passed two arguments as deep equal. This function will perform a recursive check against all of
@@ -39,9 +41,26 @@ export const isEqual = (a: any, b: any, userOptions: OptionsProps = {}) => {
3941 return true ;
4042 }
4143
42- // If we're ignoring HTML, compare the string values with HTML tags removed
43- if ( options . ignoreHtml && _ . isString ( a ) && _ . isString ( b ) && a . replace ( HTML_REGEX , '' ) === b . replace ( HTML_REGEX , '' ) ) {
44- return true ;
44+ // Deep string comparison
45+ if ( _ . isString ( a ) && _ . isString ( b ) ) {
46+ let aString = a ;
47+ let bString = b ;
48+
49+ // Remove superfluous whitespace
50+ if ( options . ignoreWhitespace ) {
51+ aString = a . replace ( WHITESPACE_REGEX , ' ' ) ;
52+ bString = b . replace ( WHITESPACE_REGEX , ' ' ) ;
53+ }
54+
55+ // If we're ignoring HTML, compare the string values with HTML tags removed
56+ if ( options . ignoreHtml ) {
57+ aString = aString . replace ( HTML_REGEX , '' ) ;
58+ bString = bString . replace ( HTML_REGEX , '' ) ;
59+ }
60+
61+ if ( aString === bString ) {
62+ return true ;
63+ }
4564 }
4665
4766 if ( a !== null && typeof a === 'object' && b !== null && typeof b === 'object' ) {
0 commit comments