Skip to main content

formatSizeStyleValue

A utility function that converts a value to <value>[suffix] format for use as a css style value.

The suffix option allows you to append a unit suffix to the value. If no option is provided, px is used as the default suffix.


Code

🔗 View source code


Interface

typescript
type SuffixUnit =
| 'cm'
| 'mm'
| 'Q'
| 'in'
| 'pc'
| 'pt'
| 'px'
| 'em'
| 'ex'
| 'ch'
| 'rem'
| 'vw'
| 'vh'
| 'vmin'
| 'vmax'
| 'lh'
| 'rlh'
| '%';

function formatSizeStyleValue(
value: number,
suffix?: SuffixUnit
): string

References


Usage

typescript
import { formatSizeStyleValue } from '@modern-kit/utils';

formatSizeStyleValue(10); // '10px'
formatSizeStyleValue(10, '%'); // '10%'