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:
parent
84a9cf7adf
commit
10f77fdf1a
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user