astro
Version:
Astro is a modern site builder with web best practices, performance, and DX front-of-mind.
12 lines (11 loc) • 394 B
JavaScript
import { FORBIDDEN_PATH_KEYS } from "@astrojs/internal-helpers/object";
export default function dlv(obj, key) {
for (const k of key.split(".")) {
if (FORBIDDEN_PATH_KEYS.has(k) || !obj || typeof obj !== "object" || !Object.hasOwn(obj, k)) {
return undefined;
}
// @ts-expect-error: Type 'unknown' is not assignable to type 'Record<string, unknown>'.
obj = obj[k];
}
return obj;
}