Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jinjor/elm-csv-decode
CSV decoder for Elm
https://github.com/jinjor/elm-csv-decode
csv decoder elm elm-lang
Last synced: 2 months ago
JSON representation
CSV decoder for Elm
- Host: GitHub
- URL: https://github.com/jinjor/elm-csv-decode
- Owner: jinjor
- License: bsd-3-clause
- Created: 2017-07-29T09:39:52.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-01T01:29:40.000Z (over 7 years ago)
- Last Synced: 2024-09-30T05:23:03.995Z (3 months ago)
- Topics: csv, decoder, elm, elm-lang
- Language: Elm
- Homepage: http://package.elm-lang.org/packages/jinjor/elm-csv-decode/latest/CsvDecode
- Size: 22.5 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
elm-csv-decode
====[![Build Status](https://travis-ci.org/jinjor/elm-csv-decode.svg)](https://travis-ci.org/jinjor/elm-csv-decode)
A CSV decoder for Elm. This library internally uses [lovasoa/elm-csv](http://package.elm-lang.org/packages/lovasoa/elm-csv/latest) for parsing. If you want to know how it parses CSV, visit it.
```elm
-- Now we are going to decode each record as User type.
type alias User =
{ id : String
, name : String
, age : Int
, mail : Maybe String
}-- You define decoder with type `Decoder User`
userDecoder : Decoder User
userDecoder =
succeed User
|= field "id"
|= field "name"
|= int (field "age")
|= optional (field "mail")-- This is the source formed of CSV.
source : String
source =
"""
id,name,age,mail
1,John Smith,20,[email protected]
2,Jane Smith,19,
"""-- Run decoder.
> CsvDecode.run userDecoder source
Ok
[ { id = "1", name = "John Smith", age = 20, mail = Just "[email protected]" }
, { id = "2", name = "Jane Smith", age = 19, mail = Nothing }
]
```Pipeline interface is inspired by [elm-tools/parser](http://package.elm-lang.org/packages/elm-tools/parser/latest/Parser).
## LICENSE
BSD-3-Clause