Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ericgj/elm-csv-decode
Decode CSV records to types
https://github.com/ericgj/elm-csv-decode
Last synced: about 2 months ago
JSON representation
Decode CSV records to types
- Host: GitHub
- URL: https://github.com/ericgj/elm-csv-decode
- Owner: ericgj
- License: bsd-3-clause
- Created: 2017-06-26T15:55:15.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-15T21:36:33.000Z (about 6 years ago)
- Last Synced: 2024-10-01T09:19:34.797Z (3 months ago)
- Language: Elm
- Size: 9.77 KB
- Stars: 2
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Csv.Decode
CSV decoding, heavily inspired by [url-parser][].
Note this library does not include an underlying CSV parser. It assumes you
are using something like [periodic/elm-csv][periodic] or
[lovasoa/elm-csv][lovasoa] to get from `String` to `Csv`, where
`Csv` is:type alias Csv =
{ headers : List String
, records : List (List String)
}This library gets you the rest of the way, to a list of your own types. It also
collects errors together with the index of the record they occurred on.You can think of this as analogous to `Json.Decode`. It lets you declaratively
convert data from an intermediate representation (`Json.Value` or `Csv`) into
your own types.## Basic usage
Using `periodic/elm-csv` (which returns a `Result (List String) Csv`):
Csv.parse rawData |> Csv.Decode.decode myDecoder
Using `lovasoa/elm-csv` (which returns a plain `Csv`):
Csv.parse rawData |> Csv.Decode.decodeCsv myDecoder
You can define decoders based on field position or on header name. See
examples in the docs.[url-parser]: https://github.com/evancz/url-parser
[periodic]: https://github.com/periodic/elm-csv
[lovasoa]: https://github.com/lovasoa/elm-csv