Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
Fixed a regression in objContains logic
Browse files Browse the repository at this point in the history
  • Loading branch information
WombatFromHell committed Jul 16, 2019
1 parent 82707fb commit 51e31b6
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,21 @@ function insertStyle(css, containerName)

function objContains(needle, haystack)
{// tests if an object (or nested object) contains a matching value (or prop)
// since objects can contains Arrays test for them too
if (isEmpty(haystack)) return false;
else {
let hopCheck = Object.prototype.hasOwnProperty(haystack, needle);
if (hopCheck) return true; // quick top level check
for (let k of Object.keys(haystack)) {
if (haystack[k] instanceof Object)
objContains(needle, haystack[k]);
else if (haystack[k] === needle)
return true;
if (haystack === needle) return true;
for (let v of Object.values(haystack)) {
if (v instanceof Object) {
let _objResult = objContains(needle, v);
if (_objResult) return true;
} else if (Array.isArray(v)) {
let _arrResult = objContains(needle, {...v});
if (_arrResult) return true;
} else if (v === needle) {
return true;
}
return false;
}
return false;
}

function superTrim(string) {
Expand Down

0 comments on commit 51e31b6

Please sign in to comment.