(
durationMs: number | undefined,
options: { field?: string; invalidMessage?: string; max?: number } = {},
)
| 23 | } |
| 24 | |
| 25 | export function normalizeScrollDurationMs( |
| 26 | durationMs: number | undefined, |
| 27 | options: { field?: string; invalidMessage?: string; max?: number } = {}, |
| 28 | ): number | undefined { |
| 29 | if (durationMs === undefined) return undefined; |
| 30 | const field = options.field ?? 'scroll durationMs'; |
| 31 | const max = options.max ?? SCROLL_DURATION_MAX_MS; |
| 32 | const invalidMessage = options.invalidMessage ?? `${field} must be a non-negative integer`; |
| 33 | if (!Number.isFinite(durationMs) || !Number.isInteger(durationMs) || durationMs < 0) { |
| 34 | throw new AppError('INVALID_ARGS', invalidMessage); |
| 35 | } |
| 36 | if (durationMs > max) { |
| 37 | throw new AppError('INVALID_ARGS', `${field} must be a non-negative integer at most ${max}`); |
| 38 | } |
| 39 | return durationMs; |
| 40 | } |
| 41 | |
| 42 | export function honoredScrollDurationMs( |
| 43 | result: Record<string, unknown> | undefined, |
no test coverage detected