convertToUnit

Commons
stable

Normalise a CSS length value: numbers become "Npx" (or any unit), CSS strings pass through untouched, and null/empty/non-finite inputs return undefined.

API

Signature

Signature TypeScript complète, extraite du fichier util.

typescript

API

Paramètres

Paramètres d'entrée acceptés par cet util.

str
requis
string | number | null | undefined
The raw value to convert. A finite number is suffixed with the unit; a string is returned as-is; null, empty string, or a non-finite number returns undefined.
unit
string
The CSS unit to append when the input is a numeric value.

API

Valeur de retour

La valeur retournée par cet util.

The normalised CSS length, or undefined when the input is null, empty, or non-finite.

Usage

Exemples

Extraits de code prêts à coller.

Numbers and CSS strings

typescript