MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / safeNum

Function safeNum

packages/core/src/runtime/player.ts:9–17  ·  view source on GitHub ↗

* Safely read a numeric value from a timeline property that may be either a * function (conformant GSAP) or a bare number (user-authored timeline-like).

(obj: unknown, prop: string, fallback: number)

Source from the content-addressed store, hash-verified

7 * function (conformant GSAP) or a bare number (user-authored timeline-like).
8 */
9function safeNum(obj: unknown, prop: string, fallback: number): number {
10 const val = (obj as Record<string, unknown>)?.[prop];
11 if (typeof val === "function") return Number(val.call(obj)) || fallback;
12 if (typeof val === "number" && Number.isFinite(val)) return val;
13 if (val !== undefined && val !== null) {
14 swallow("runtime.player.nonConformantNum", { prop, actual: typeof val });
15 }
16 return fallback;
17}
18
19/**
20 * Safely invoke a void method on a timeline. If the method is not a function

Callers 1

createRuntimePlayerFunction · 0.85

Calls 1

swallowFunction · 0.90

Tested by

no test coverage detected