12 lines
393 B
TypeScript
12 lines
393 B
TypeScript
function getNested(obj: any, path: string): any {
|
|
return path.split(".").reduce((o, k) => o?.[k], obj);
|
|
}
|
|
|
|
export function applyDisplayFormat(item: any, format: string): string {
|
|
if (!item || typeof item !== "object") return String(item ?? "");
|
|
return format.replace(/\{([\w.]+)\}/g, (_, key) => {
|
|
const val = getNested(item, key);
|
|
return val != null ? String(val) : "";
|
|
});
|
|
}
|