Skip to content

The open alternative to Salesforce, designed for AI.

567 B
Raw Blame
import { isNumber } from '@sniptt/guards';

import { UNITLESS_CSS_PROPERTY_NAMES } from '@/constants/UnitlessCssPropertyNames';
import { isCssCustomPropertyName } from '@/utils/css/isCssCustomPropertyName';

export const formatCssValue = (
  value: unknown,
  stylePropertyName: string,
): string => {
  const shouldAppendPixelUnitToNumber =
    isNumber(value) &&
    value !== 0 &&
    !isCssCustomPropertyName(stylePropertyName) &&
    !UNITLESS_CSS_PROPERTY_NAMES.has(stylePropertyName);

  return shouldAppendPixelUnitToNumber ? `${value}px` : String(value);
};