Surgex.Parser.StringParser (Surgex v6.0.1)

View Source

Available options:

  • trim is trimming whitespaces from the string, takes priority over min and max options
  • min is a minimal length of the string, returns :too_short error symbol
  • max is a maximal length of the string, returns :too_long error symbol
  • regex - input string must match passed regular expression, this is done after trimming

Summary

Types

errors()

@type errors() :: :too_short | :too_long | :invalid_string | :bad_format

option()

@type option() ::
  {:trim, boolean()}
  | {:min, integer()}
  | {:max, integer()}
  | {:regex, Regex.t()}

Functions

call(input, opts \\ [])

@spec call(term(), [option()]) :: {:ok, String.t() | nil} | {:error, errors()}

check_regex(input)

@spec check_regex(%{opts: list(), value: String.t(), error: nil}) :: %{
  opts: list(),
  value: String.t(),
  error: nil | :bad_format
}

trim(input)

@spec trim(%{opts: list(), value: String.t(), error: nil}) :: %{
  opts: list(),
  value: String.t(),
  error: nil
}

validate_max(input)

@spec validate_max(%{opts: list(), value: String.t(), error: nil}) :: %{
  opts: list(),
  value: String.t(),
  error: nil | :too_long
}

validate_min(input)

@spec validate_min(%{opts: list(), value: String.t(), error: nil}) :: %{
  opts: list(),
  value: String.t(),
  error: nil | :too_short
}