This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
1.0.0
CSV Decoder for Elm
version 1.0.1
license BSD-3-Clause
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 1.0.1
Committed At 2017-08-01 01:28:04 UTC
lovasoa/elm-csv 1.1.4 <= v < 2.0.0 1.1.5
elm-lang/html 2.0.0 <= v < 3.0.0 2.0.0
elm-lang/core 5.1.1 <= v < 6.0.0 5.1.1

Modules

README

elm-csv-decode

Build Status

A CSV decoder for Elm. This library internally uses lovasoa/elm-csv for parsing. If you want to know how it parses CSV, visit it.

-- 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,john@example.com
2,Jane Smith,19,
"""


-- Run decoder.
> CsvDecode.run userDecoder source
Ok
    [ { id = "1", name = "John Smith", age = 20, mail = Just "john@example.com" }
    , { id = "2", name = "Jane Smith", age = 19, mail = Nothing }
    ]

Pipeline interface is inspired by elm-tools/parser.

LICENSE

BSD-3-Clause