View Source Appwrite.Consts.Flag (appwrite v0.1.9)

Provides constants and validation functions for country flags.

This module defines the country flags by their ISO 3166-1 alpha-2 code and provides helper functions to validate them, ensuring only recognized country flags are used within the application.

Summary

Functions

Returns true if the given flag is a valid country flag code.

Guard clause to check if a given flag is a valid country flag code.

Validates the given flag and returns {:ok, flag} if it is valid, or {:error, "Invalid country flag code"} otherwise.

Returns the given flag if it is valid. Raises an ArgumentError if the flag is invalid.

Functions

is_valid_flag?(flag)

@spec is_valid_flag?(String.t()) :: boolean()

Returns true if the given flag is a valid country flag code.

Examples

iex> Flag.is_valid_flag?("us")
true

iex> Flag.is_valid_flag?("xx")
false

valid_flag(flag)

(macro)
@spec valid_flag(String.t()) :: boolean()

Guard clause to check if a given flag is a valid country flag code.

Examples

iex> Flag.valid_flag("in")
true

iex> Flag.valid_flag("xx")
false

validate_flag(flag)

@spec validate_flag(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Validates the given flag and returns {:ok, flag} if it is valid, or {:error, "Invalid country flag code"} otherwise.

Examples

iex> Flag.validate_flag("ca")
{:ok, "ca"}

iex> Flag.validate_flag("xx")
{:error, "Invalid country flag code"}

validate_flag!(flag)

@spec validate_flag!(String.t()) :: String.t()

Returns the given flag if it is valid. Raises an ArgumentError if the flag is invalid.

Examples

iex> Flag.validate_flag!("fr")
"fr"

iex> Flag.validate_flag!("xx")
** (ArgumentError) Invalid country flag code: "xx"