Delimit.Formats (delimit v0.2.0)

View Source

Standard format configurations for common delimited file types.

This module provides predefined format configurations for common file formats such as CSV (comma-separated values), TSV (tab-separated values), PSV (pipe-separated values), and SSV (semi-colon separated values).

Using these formats simplifies configuration by setting appropriate defaults for delimiter, escape character, and other format-specific options.

Summary

Functions

Returns configuration options for a specified file format.

Merges format options with custom options.

Lists all supported format identifiers.

Functions

get_options(format)

@spec get_options(atom()) :: Keyword.t()

Returns configuration options for a specified file format.

Parameters

  • format - The format identifier (:csv, :tsv, :psv)

Returns

  • A keyword list of options appropriate for the specified format

Examples

iex> Delimit.Formats.get_options(:csv)
[delimiter: ",", escape: """]

iex> Delimit.Formats.get_options(:tsv)
[delimiter: "\t", escape: """]

merge_options(schema_options, format, custom_options)

@spec merge_options(Keyword.t(), atom() | nil, Keyword.t()) :: Keyword.t()

Merges format options with custom options.

Format options take precedence over schema defaults but are overridden by explicitly provided custom options.

Parameters

  • schema_options - Base options from the schema
  • format - The format identifier, or nil for no format
  • custom_options - Custom options that will override format options

Returns

  • A keyword list of merged options

Examples

iex> schema_opts = [trim_fields: false]
iex> Delimit.Formats.merge_options(schema_opts, :csv, [escape: "'"])
[trim_fields: false, delimiter: ",", escape: "'"]

supported_formats()

@spec supported_formats() :: [atom()]

Lists all supported format identifiers.

Returns

  • A list of supported format atoms

Examples

iex> Delimit.Formats.supported_formats()
[:csv, :tsv, :psv, :ssv]