CsvSniffer (CsvSniffer v0.2.2)

View Source

An Elixir port of Python's CSV Sniffer.

Summary

Functions

"Sniffs" the format of a CSV sample (i.e. delimiter, quote character).

Functions

sniff(sample, opts \\ [])

(since 0.2.0)
@spec sniff(sample :: String.t(), opts :: [{:delimiters, [String.t()]}]) ::
  {:ok, CsvSniffer.Dialect.t()} | {:error, reason :: any()}

"Sniffs" the format of a CSV sample (i.e. delimiter, quote character).

Options

  • :delimiters - Limit the sniffer to a list of possible delimiters.

Examples

iex> """
...> Harry's, Arlington Heights, IL, 2/1/03, Kimi Hayes
...> Shark City, Glendale Heights, IL, 12/28/02, Prezence
...> Tommy's Place, Blue Island, IL, 12/28/02, Blue Sunday/White Crow
...> Stonecutters Seafood and Chop House, Lemont, IL, 12/19/02, Week Back
...> """
...> |> CsvSniffer.sniff()
{:ok, %CsvSniffer.Dialect{
  delimiter: ",",
  quote_character: "\"",
  double_quote: false,
  skip_initial_space: true
}}