parseHex

Commons
stable

Normalise any hex color string — with or without leading `#`, short-form (3/4 digits) or long-form (6/8 digits) — into a canonical 6-character `THex` string, replacing invalid characters with `F`.

API

Signature

Signature TypeScript complète, extraite du fichier util.

typescript

API

Paramètres

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

hex
requis
string
A hex color string in any accepted format: with or without `#`, 3/4/6/8 digit. Invalid characters are silently coerced to `F`.

API

Valeur de retour

La valeur retournée par cet util.

A normalised 6-character uppercase hex string (e.g. `"3B82F6"`). Invalid inputs are padded/coerced rather than throwing.

Usage

Exemples

Extraits de code prêts à coller.

Normalise hex color strings

typescript