1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

permit non strict comparison of string or number

This commit is contained in:
Stephen McLaughlin 2022-03-08 23:13:41 +00:00 committed by GitHub
parent 84a9cf7adf
commit 10f77fdf1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -139,17 +139,23 @@
}
});
/**
* Compares `v1` with `v2` for equality
* @param {*} v1 variable 1
* @param {*} v2 variable 2
* @returns {boolean} true if variable 1 equals variable 2, otherwise false
* Compares `newValue` with `originalValue` for equality.
* NOTES:
* * If `newValue` is a string or number, comparison is not strict
* * If `newValue` is anything else, comparison is strict
* @param {*} originalValue Original value
* @param {*} newValue New value
* @returns {boolean} true if originalValue equals newValue, otherwise false
*/
function isEqual(v1, v2) {
function isEqual(originalValue, newValue) {
try {
if(v1 === v2) {
return true;
if (typeof newValue === "string" || typeof newValue === "number") {
return originalValue == newValue;
}
return JSON.stringify(v1) === JSON.stringify(v2);
if (typeof newValue === "boolean") {
return originalValue === newValue;
}
return JSON.stringify(originalValue) === JSON.stringify(newValue);
} catch (err) {
return false;
}