MCPcopy
hub / github.com/davidhu2000/react-spinners / parseLengthAndUnit

Function parseLengthAndUnit

src/helpers/unitConverter.ts:33–63  ·  view source on GitHub ↗
(size: number | string)

Source from the content-addressed store, hash-verified

31 * @return {LengthObject} LengthObject
32 */
33export function parseLengthAndUnit(size: number | string): LengthObject {
34 if (typeof size === "number") {
35 return {
36 value: size,
37 unit: "px",
38 };
39 }
40 let value: number;
41 const valueString: string = (size.match(/^[0-9.]*/) || "").toString();
42 if (valueString.includes(".")) {
43 value = parseFloat(valueString);
44 } else {
45 value = parseInt(valueString, 10);
46 }
47
48 const unit: string = (size.match(/[^0-9]*$/) || "").toString();
49
50 if (cssUnit[unit]) {
51 return {
52 value,
53 unit,
54 };
55 }
56
57 console.warn(`React Spinners: ${size} is not a valid css value. Defaulting to ${value}px.`);
58
59 return {
60 value,
61 unit: "px",
62 };
63}
64
65/**
66 * Take value as an input and return valid css value

Callers 13

styleFunction · 0.90
PacmanLoaderFunction · 0.90
RotateLoaderFunction · 0.90
MoonLoaderFunction · 0.90
GridLoaderFunction · 0.90
RingLoaderFunction · 0.90
PropagateLoaderFunction · 0.90
HashLoaderFunction · 0.90
FadeLoaderFunction · 0.90
styleFunction · 0.90
ClockLoaderFunction · 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…