MCPcopy Create free account
hub / github.com/bernaferrari/FigmaToCode / pxToTailwind

Function pxToTailwind

packages/backend/src/tailwind/conversionTables.ts:74–93  ·  view source on GitHub ↗
(
  value: number,
  conversionMap: Record<number, string>,
)

Source from the content-addressed store, hash-verified

72};
73
74const pxToTailwind = (
75 value: number,
76 conversionMap: Record<number, string>,
77): string | null => {
78 const keys = Object.keys(conversionMap).map((d) => +d);
79 const convertedValue = exactValue(value, keys);
80
81 if (convertedValue) {
82 return conversionMap[convertedValue];
83 } else if (localTailwindSettings.roundTailwindValues) {
84 // Only round if the nearest value is within acceptable threshold
85 const thresholdValue = nearestValueWithThreshold(value, keys);
86
87 if (thresholdValue !== null) {
88 return conversionMap[thresholdValue];
89 }
90 }
91
92 return `[${numberToFixedString(value)}px]`;
93};
94
95export const pxToLetterSpacing = (value: number): string => {
96 return pxToRemToTailwind(value, config.letterSpacing);

Callers 4

pxToBorderWidthFunction · 0.85
pxToOutlineFunction · 0.85
pxToBlurFunction · 0.85
pxToLayoutSizeFunction · 0.85

Calls 3

numberToFixedStringFunction · 0.90
exactValueFunction · 0.85

Tested by

no test coverage detected