(sampleRate: unknown)
| 6 | * Any invalid sample rate will return `undefined`. |
| 7 | */ |
| 8 | export function parseSampleRate(sampleRate: unknown): number | undefined { |
| 9 | if (typeof sampleRate === 'boolean') { |
| 10 | return Number(sampleRate); |
| 11 | } |
| 12 | |
| 13 | const rate = typeof sampleRate === 'string' ? parseFloat(sampleRate) : sampleRate; |
| 14 | if (typeof rate !== 'number' || isNaN(rate) || rate < 0 || rate > 1) { |
| 15 | return undefined; |
| 16 | } |
| 17 | |
| 18 | return rate; |
| 19 | } |
no outgoing calls
no test coverage detected