* 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)
| 7 | * function (conformant GSAP) or a bare number (user-authored timeline-like). |
| 8 | */ |
| 9 | function 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 |
no test coverage detected