(scrollThreshold: string | number)
| 9 | }; |
| 10 | |
| 11 | export function parseThreshold(scrollThreshold: string | number) { |
| 12 | if (typeof scrollThreshold === 'number') { |
| 13 | return { |
| 14 | unit: ThresholdUnits.Percent, |
| 15 | value: scrollThreshold * 100, |
| 16 | }; |
| 17 | } |
| 18 | |
| 19 | if (typeof scrollThreshold === 'string') { |
| 20 | if (/^(\d*(\.\d+)?)px$/.exec(scrollThreshold)) { |
| 21 | return { |
| 22 | unit: ThresholdUnits.Pixel, |
| 23 | value: parseFloat(scrollThreshold), |
| 24 | }; |
| 25 | } |
| 26 | |
| 27 | if (/^(\d*(\.\d+)?)%$/.exec(scrollThreshold)) { |
| 28 | return { |
| 29 | unit: ThresholdUnits.Percent, |
| 30 | value: parseFloat(scrollThreshold), |
| 31 | }; |
| 32 | } |
| 33 | |
| 34 | console.warn( |
| 35 | 'scrollThreshold format is invalid. Valid formats: "120px", "50%"...' |
| 36 | ); |
| 37 | |
| 38 | return defaultThreshold; |
| 39 | } |
| 40 | |
| 41 | console.warn('scrollThreshold should be string or number'); |
| 42 | |
| 43 | return defaultThreshold; |
| 44 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…