Confispex.Type.CSV (confispex v1.1.0)

A CSV type.

Casts a CSV string to a list with values which are cast according to :of option.

Options

Examples

iex> Confispex.Type.cast("John,user1@example.com", Confispex.Type.CSV)
{:ok, ["John", "user1@example.com"]}

iex> Confispex.Type.cast("John,user1@example.com", {Confispex.Type.CSV, of: Confispex.Type.Email})
{:error,
 {"John,user1@example.com", {Confispex.Type.CSV, [of: Confispex.Type.Email]},
  [
    nested: [
      {"John", Confispex.Type.Email,
       [parsing: ["expected a string in format ", {:highlight, "username@host"}]]}
    ]
  ]}}

iex> Confispex.Type.cast(~s|John,"user1@example.com|, Confispex.Type.CSV)
{:error,
 {~s|John,"user1@example.com|, Confispex.Type.CSV,
  [parsing: ~s|expected escape character " but reached the end of file|]}}