Skip to content

isHexColor ​

A função isHexColor verifica se uma string representa uma cor hexadecimal válida.

Sintaxe ​

typescript
isHexColor(hex: string): boolean;

Parâmetros ​

NomeTipoDescrição
hexstringCor em formato hexadecimal

Retorno ​

TipoDescrição
booleanRetorna true se for uma cor hexadecimal

Exemplos ​

typescript
isHexColor("#ff0000");
// => true

isHexColor("#f00");
// => true

isHexColor("rgb(255, 0, 0)");
// => false

Notas ​

  • Aceita formatos curtos (#fff) e longos (#ffffff), com ou sem canal alfa.

Referências ​

Released under the MIT License.