MCPcopy Create free account
hub / github.com/donghaxkim/react-rewrite / parseTranslateClassPx

Function parseTranslateClassPx

packages/cli/src/batch-transform.ts:946–965  ·  view source on GitHub ↗

* Parse a Tailwind translate class (e.g., "translate-x-6", "-translate-y-4", "translate-x-[32px]") * back to a signed pixel value.

(cls: string, basePrefix: string)

Source from the content-addressed store, hash-verified

944 * back to a signed pixel value.
945 */
946function parseTranslateClassPx(cls: string, basePrefix: string): number {
947 const isNeg = cls.startsWith("-");
948 // Strip leading "-" and the prefix + "-" to get the token
949 const stripped = isNeg ? cls.slice(1) : cls;
950 const token = stripped.slice(basePrefix.length + 1); // +1 for the "-" separator
951
952 // Arbitrary value: [Npx]
953 const arbMatch = token.match(/^\[(-?\d+(?:\.\d+)?)px\]$/);
954 if (arbMatch) {
955 return (isNeg ? -1 : 1) * parseFloat(arbMatch[1]);
956 }
957
958 // Standard token
959 const px = SPACING_TOKEN_PX[token];
960 if (px != null) {
961 return (isNeg ? -1 : 1) * px;
962 }
963
964 return 0; // unknown token, treat as 0
965}
966
967/**
968 * Snap an absolute pixel value to the nearest Tailwind spacing token.

Callers 1

applyOpFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected