{"id":13507724,"url":"https://github.com/CargoSense/ex_csv","last_synced_at":"2025-03-30T09:33:01.744Z","repository":{"id":20889231,"uuid":"24176578","full_name":"CargoSense/ex_csv","owner":"CargoSense","description":"CSV for Elixir","archived":true,"fork":false,"pushed_at":"2016-06-29T22:50:54.000Z","size":29,"stargazers_count":46,"open_issues_count":1,"forks_count":8,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-05T12:48:50.284Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"jenkinsci/blueocean-plugin","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CargoSense.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-18T06:24:31.000Z","updated_at":"2024-10-27T03:22:52.000Z","dependencies_parsed_at":"2022-09-15T15:10:12.839Z","dependency_job_id":null,"html_url":"https://github.com/CargoSense/ex_csv","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CargoSense%2Fex_csv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CargoSense%2Fex_csv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CargoSense%2Fex_csv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CargoSense%2Fex_csv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CargoSense","download_url":"https://codeload.github.com/CargoSense/ex_csv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246301963,"owners_count":20755512,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:00:38.202Z","updated_at":"2025-03-30T09:33:01.411Z","avatar_url":"https://github.com/CargoSense.png","language":"Elixir","funding_links":[],"categories":["CSV"],"sub_categories":[],"readme":"ExCsv\n=====\n\nElixir CSV.\n\nNote: Currently only supports parsing.\n\n## Usage\n\n### Parsing\n\nParsing a file gives you a `ExCsv.Table` struct:\n\n```elixir\nFile.read!(\"foo/bar.csv\") |\u003e ExCsv.parse\n# =\u003e {:ok, %ExCsv.Table{...}}\n```\n\n(You can alse use `ExCsv.parse!/1` which will raise an error instead\nof returning an `{:error, err}` tuple if parsing fails.)\n\nIf your CSV has headings, you can let the parser know up front:\n\n```elixir\n{:ok, table} = File.read!(\"foo/bar.csv\") |\u003e ExCsv.parse(headings: true)\n# =\u003e {:ok, %ExCsv.Table{...}}\ntable.headings\n# =\u003e [\"Person\", \"Current Age\"]\n```\n\nOr you can use `ExCsv.with_headings/1` afterwards:\n\n```elixir\n{:ok, table} = File.read!(\"foo/bar.csv\")\n               |\u003e ExCsv.parse!\n               |\u003e ExCsv.with_headings\n# =\u003e %ExCsv.Table{...}\ntable.headings\n# =\u003e [\"Person\", \"Current\"]\n```\n\nYou can also change the set or change headings by using\n`ExCsv.with_headings/2`:\n\n```elixir\ntable = File.read!(\"foo/bar.csv\")\n        |\u003e ExCsv.parse!\n        |\u003e ExCsv.with_headings([\"name\", \"age\"])\n# =\u003e %ExCsv.Table{...}\ntable.headings\n# =\u003e [\"name\", \"age\"]\n```\n\nIf you need to parse a format that uses another delimiter character,\nyou can set it as an option (note the single quotes):\n\n```elixir\ntable = File.read!(\"foo/bar.csv\") |\u003e ExCsv.parse!(delimiter: ';')\n# =\u003e %ExCsv.Table{...}\n```\n\nOnce you have a `ExCsv.Table`, you can use its `headings` and `body`\ndirectly -- or you enumerate over the table.\n\n## Enumerating\n\nIf your `ExCsv.Table` struct does not have headers, iterating over it\nwill result in a list for each row:\n\n```elixir\ntable = File.read!(\"foo/bar.csv\")\n        |\u003e ExCsv.parse!\n        |\u003e Enum.to_list\n# [[\"Jayson\", 23], [\"Jill\", 34], [\"Benson\", 45]]\n```\n\nIf your table has headings, you'll get maps:\n\n```elixir\ntable = File.read!(\"foo/bar.csv\")\n        |\u003e ExCsv.parse!(headings: true)\n        |\u003e ExCsv.with_headings([:name, :age])\n        |\u003e Enum.to_list\n# [%{name: \"Jayson\", age: 23},\n#  %{name: \"Jill\", age: 34},\n#  %{name: \"Benson\", age: 45}]\n```\n\nYou can build structs from the rows by using `ExCsv.as/1` (if the\nheadings match the struct attributes):\n\n```elixir\ntable = File.read!(\"foo/bar.csv\")\n        |\u003e ExCsv.parse!(headings: true)\n        |\u003e ExCsv.with_headings([:name, :age])\n        |\u003e ExCsv.as(Person)\n        |\u003e Enum.to_list\n# [%Person{name: \"Jayson\", age: 23},\n#  %Person{name: \"Jill\", age: 34},\n#  %Person{name: \"Benson\", age: 45}]\n```\n\nIf the headings don't match the struct attributes, you can provide a\nmapping (of CSV heading name to struct attribute name) with\n`ExCsv.as/2`:\n\n```elixir\ntable = File.read!(\"books.csv\")\n        |\u003e ExCsv.parse!(headings: true)\n        |\u003e ExCsv.as(Author, %{\"name\" =\u003e :title, \"author\" =\u003e :name})\n        |\u003e Enum.to_list\n# [%Author{name: \"John Scalzi\", title: \"A War for Old Men\"},\n#  %Author{name: \"Margaret Atwood\", title: \"A Handmaid's Tale\"}]\n```\n\n## Contributing\n\nPlease fork and send pull requests (preferably from non-master\nbranches), including tests (`ExUnit.Case`).\n\nReport bugs and request features via Issues; PRs are even better!\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2014 CargoSense, Inc.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCargoSense%2Fex_csv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCargoSense%2Fex_csv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCargoSense%2Fex_csv/lists"}