Pote.Validator (Pote v1.0.0)

Copy Markdown View Source

Validates color format values against their specification.

Supported Formats

  • hex:RRGGBB - 6 hexadecimal characters (0-9, A-F, a-f)
  • rgb:R,G,B - Three integers 0-255
  • argb:A,R,G,B - Alpha 255, then R,G,B 0-255
  • xterm:N - Integer 0-255
  • hsl:H,S,L - H: 0-360 (degrees, 2 decimals), S/L: 0-100 (percentage, 4 decimals)
  • hsv:H,S,V - H: 0-360 (degrees, 2 decimals), S/V: 0-100 (percentage, 4 decimals)
  • cmyk:C,M,Y,K - Each 0-100 (percentage, 4 decimals)

Usage

iex> Pote.Validator.validate("hex:FF0000")
:ok

iex> Pote.Validator.validate("rgb:256,0,0")
{:error, :rgb_value_out_of_range}

iex> Pote.Validator.validate("hsl:370,50,50")
{:error, :hue_out_of_range}

Summary

Functions

Returns a human-readable error message for a validation error.

Validates a color input string with format prefix.

Types

validation_result()

@type validation_result() :: :ok | {:error, atom()} | {:error, atom(), String.t()}

Functions

error_message(reason)

@spec error_message(atom()) :: String.t()

Returns a human-readable error message for a validation error.

validate(input)

@spec validate(String.t()) :: validation_result()

Validates a color input string with format prefix.

Returns :ok if all values are valid, or {:error, reason} or {:error, reason, detail} if not.