Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hermanverschooten/csv_generator
Simple CSV generator
https://github.com/hermanverschooten/csv_generator
csv elixir
Last synced: 3 months ago
JSON representation
Simple CSV generator
- Host: GitHub
- URL: https://github.com/hermanverschooten/csv_generator
- Owner: Hermanverschooten
- License: mit
- Created: 2020-03-29T14:17:18.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-25T14:32:44.000Z (9 months ago)
- Last Synced: 2024-04-25T15:43:13.131Z (9 months ago)
- Topics: csv, elixir
- Language: Elixir
- Homepage:
- Size: 22.5 KB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
This library provides an easy way to generate CSV files.
It allows you to define the colums and their respective types.## Example
defmodule MyCSV do
use CsvGeneratorcolumn :name, :string
column :joined, :date, format: "%d-%m-%Y"
column :points, :integer, label: "points earned"
hardcoded :string, "Game", "domino"
endYou would then render the CSV bij calling the `render/1` method with
the list of lines to render.## Example
iex> MyCSV.render([
%{ name: "Chris McCord", joined: ~D[2020-01-01], points: 110},
%{ name: "Jose Valim", joined: ~D[2020-03-29], points: 10} ])
"\"name\",\"joined\",\"points earned\",\"Game\"\n\"Chris McCord\",01-01-2020,110,\"domino\"\n\"Jose Valim\",29-03-2020,10,\"domino\""By default the CSV columns will be seperated by a `","`, the lines by a `"\n"`.
This can be changed by using `delimiter` and `line_ending`.## Example
defmodule MyCSV do
use CsvGeneratordelimiter ";"
line_ending "\r\n"column :name, :string
column :birthday, :date, format: "%d-%m-%Y"
column :points, :integer
endiex> MyCSV.render([
%{ name: "Jose Valim", joined: ~D[2020-03-29], points: 10} ])
"\"name\";\"joined\";\"points earned\"\n\"Jose Valim\";29-03-2020;10"# Formatting
A formatter is included, to be able to have `mix format` use it, you have to add it to your own `.formatter.exs` in `import_deps`.
## Example
[
import_deps: [:ecto, :phoenix, :csv_generator],
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
subdirectories: ["priv/*/migrations"]
]