mirror of
https://github.com/morten-olsen/homelab-operator.git
synced 2026-02-08 01:36:28 +01:00
34 lines
846 B
TypeScript
34 lines
846 B
TypeScript
const isDeepSubset = (actual: ExpectedAny, expected: ExpectedAny): boolean => {
|
|
if (typeof expected !== 'object' || expected === null) {
|
|
return actual === expected;
|
|
}
|
|
|
|
if (typeof actual !== 'object' || actual === null) {
|
|
return false;
|
|
}
|
|
|
|
if (Array.isArray(expected)) {
|
|
if (!Array.isArray(actual)) {
|
|
return false;
|
|
}
|
|
return expected.every((expectedItem) => actual.some((actualItem) => isDeepSubset(actualItem, expectedItem)));
|
|
}
|
|
|
|
// Iterate over the keys of the expected object
|
|
for (const key in expected) {
|
|
if (Object.prototype.hasOwnProperty.call(expected, key)) {
|
|
if (!Object.prototype.hasOwnProperty.call(actual, key)) {
|
|
return false;
|
|
}
|
|
|
|
if (!isDeepSubset(actual[key], expected[key])) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
export { isDeepSubset };
|