Skip to content

Commit 39b9511

Browse files
authored
Merge pull request #108 from performant-software/feature/archnet587_unsaved_changes
Archnet #587 - Unsaved changes
2 parents f19513a + e249fc9 commit 39b9511

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/utils/Object.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ const EMPTY_VALUES = [
1717

1818
const DEFAULT_OPTIONS = {
1919
emptyValues: EMPTY_VALUES,
20-
ignoreHtml: true
20+
ignoreHtml: true,
21+
ignoreWhitespace: true
2122
};
2223

2324
const 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

Comments
 (0)