(
record: Record<string, unknown>,
key: string,
options: { min?: number; max?: number } = {},
)
| 390 | } |
| 391 | |
| 392 | export function optionalInteger( |
| 393 | record: Record<string, unknown>, |
| 394 | key: string, |
| 395 | options: { min?: number; max?: number } = {}, |
| 396 | ): number | undefined { |
| 397 | const value = record[key]; |
| 398 | if (value === undefined) return undefined; |
| 399 | if (!Number.isInteger(value)) { |
| 400 | throw new Error(`Expected ${key} to be an integer.`); |
| 401 | } |
| 402 | const numberValue = value as number; |
| 403 | if (options.min !== undefined && numberValue < options.min) { |
| 404 | throw new Error(`Expected ${key} to be at least ${options.min}.`); |
| 405 | } |
| 406 | if (options.max !== undefined && numberValue > options.max) { |
| 407 | throw new Error(`Expected ${key} to be at most ${options.max}.`); |
| 408 | } |
| 409 | return numberValue; |
| 410 | } |
| 411 | |
| 412 | function optionalBoolean(record: Record<string, unknown>, key: string): boolean | undefined { |
| 413 | const value = record[key]; |
no outgoing calls
no test coverage detected