2024-10-01 10:55:48 -04:00
|
|
|
function hasNestedValue(obj, path, delimiter = "_") {
|
|
|
|
|
const keys = path.split(delimiter);
|
|
|
|
|
let current = obj;
|
|
|
|
|
|
|
|
|
|
for (const key of keys) {
|
2024-10-01 11:37:07 -04:00
|
|
|
while(Array.isArray(current) && current.length == 1 && current[0]){
|
|
|
|
|
current = current[0]
|
|
|
|
|
}
|
|
|
|
|
while(current['value']){
|
|
|
|
|
current = current.value
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-01 10:55:48 -04:00
|
|
|
if (current && typeof current === "object") {
|
|
|
|
|
if (Array.isArray(current)) {
|
|
|
|
|
const index = current.findIndex(x => x == key)
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
current = current[index];
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else if (key in current) {
|
2024-10-01 00:14:55 -04:00
|
|
|
current = current[key];
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-10-01 10:55:48 -04:00
|
|
|
} else {
|
|
|
|
|
return false;
|
2024-10-01 00:14:55 -04:00
|
|
|
}
|
2024-10-01 10:55:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2024-10-01 00:14:55 -04:00
|
|
|
}
|
2024-10-01 10:55:48 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = { hasNestedValue};
|