https://github.com/ghivert/elm-data-dumper
Dump data structure easily in Elm!
https://github.com/ghivert/elm-data-dumper
data-structures elm formatter
Last synced: 10 months ago
JSON representation
Dump data structure easily in Elm!
- Host: GitHub
- URL: https://github.com/ghivert/elm-data-dumper
- Owner: ghivert
- License: mit
- Created: 2017-07-27T19:13:35.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-06-21T14:30:15.000Z (almost 8 years ago)
- Last Synced: 2025-02-15T14:47:35.071Z (over 1 year ago)
- Topics: data-structures, elm, formatter
- Language: Elm
- Homepage: http://package.elm-lang.org/packages/ghivert/elm-data-dumper/latest
- Size: 30.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Elm Data Dumper
This package provides facilities to dump data structures in HTML.
Contrary to `Debug.log`, which dump everything to the console, Data.Dumper give colors to the output, and format to be easier to read.
You just have to code the dumper when making your structure, and yay! You can dump freely data structures in HTML!
# An Example?
```elm
import Html exposing (Html)
type alias Location =
{ host : String
, hostname : String
, protocol : String
}
type Locations
= Nowhere
| Loc Location
dumpLocation : Location -> Html msg
dumpLocation =
dumpRecord "Location"
[ ("host", .host >> dumpString)
, ("hostname", .hostname >> dumpString)
, ("protocol", .protocol >> dumpString)
]
dumpNestedLocation : Location -> Html msg
dumpNestedLocation =
dumpNestedRecord 1
[ ("host", .host >> dumpString)
, ("hostname", .hostname >> dumpString)
, ("protocol", .protocol >> dumpString)
]
dumpLocations : Locations -> Html msg
dumpLocations locations =
dumpUnion "Locations" <|
case locations of
Nowhere ->
("Nowhere", Html.text "")
Loc location ->
("Loc", dumpNestedLocation location)
main : Html msg
main =
let example = Location "host_" "hostname_" "protocol_" in
Html.div []
[ dumpLocation example
, dumpLocations Nowhere
, dumpLocations <| Loc example
]
```
Turn into this:
