Pote.Sanitizer (Pote v3.0.0)

Copy Markdown View Source

Handles cleaning user input for colour formats.

Its purpose is to strip unit symbols (%, º, deg) from numeric values so that format modules can parse them without errors.

Summary

Functions

Cleans a string by removing common unit suffixes. Examples

Cleans a list of strings or a delimiter-separated string. Useful for inputs like "360º, 50%, 50%".

Functions

sanitize(input)

@spec sanitize(String.t()) :: String.t()

Cleans a string by removing common unit suffixes. Examples:

  • "360º" -> "360"
  • "50%" -> "50"
  • "12.5 deg" -> "12.5"

Raises ArgumentError if the input is not a binary. Use sanitize_list/2 for non-binary inputs (lists) or pre-validate.

sanitize_list(input, separator)

@spec sanitize_list(any(), String.t() | nil) ::
  {:ok, [String.t()]} | {:error, atom() | String.t()}

Cleans a list of strings or a delimiter-separated string. Useful for inputs like "360º, 50%, 50%".

The binary variant returns {:error, :invalid_input} if the separator is invalid (not a binary). The list variant returns {:error, :invalid_input} if the input is not a list.