MCPcopy
hub / github.com/ankeetmaini/react-infinite-scroll-component / parseThreshold

Function parseThreshold

src/utils/threshold.ts:11–44  ·  view source on GitHub ↗
(scrollThreshold: string | number)

Source from the content-addressed store, hash-verified

9};
10
11export 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}

Callers 2

buildRootMarginFunction · 0.90
threshold.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…