import type { Resource } from "@src/tems"; const filterObjectById = ( array: Resource[], propName: string, targetId: string ): Resource[] => { if (!propName || !targetId) { return array; } return array.filter((obj) => { let current = obj; const propPath = propName.split("."); for (const segment of propPath) { if (current && typeof current === "object" && segment in current) { current = current[segment]; } else { return false; } } const propValue = current; if (!propValue) { return false; } if ( typeof propValue === "object" && !Array.isArray(propValue) && propValue !== null && "@id" in propValue && propValue["@id"] === targetId ) { return true; } if (Array.isArray(propValue)) { return propValue.some( (item) => typeof item === "object" && item !== null && "@id" in item && item["@id"] === targetId ); } return false; }); }; export default filterObjectById;