Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tsfoster/elm-envfile
Parser and encoder for envfiles in Elm
https://github.com/tsfoster/elm-envfile
elm elm-lang elmlang envfile environment-variables
Last synced: about 1 month ago
JSON representation
Parser and encoder for envfiles in Elm
- Host: GitHub
- URL: https://github.com/tsfoster/elm-envfile
- Owner: TSFoster
- License: bsd-3-clause
- Created: 2018-12-04T16:22:04.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-09T22:07:30.000Z (over 5 years ago)
- Last Synced: 2024-11-21T00:59:28.439Z (about 1 month ago)
- Topics: elm, elm-lang, elmlang, envfile, environment-variables
- Language: Elm
- Homepage: https://package.elm-lang.org/packages/TSFoster/elm-envfile/latest/
- Size: 39.1 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# elm-envfile
Parser and encoder for envfile file format, following simple definition provided
by [Docker](https://docs.docker.com/compose/env-file/).## Examples
### Parsing
```elm
import Dict
import Envfile
import Parser[ "linesInThisFile=7"
, "numberOfDefinitions=5"
, "containsBlankLines=TRUE"
, ""
, "# Commented line"
, "ENV=development"
, "Thing="
]
|> String.join "\n"
|> Parser.run Envfile.parser
--> Ok <| Dict.fromList
--> [ ("linesInThisFile", "7")
--> , ("numberOfDefinitions", "5")
--> , ("containsBlankLines", "TRUE")
--> , ("ENV", "development")
--> , ("Thing", "")
--> ]
``````elm
import Envfile
import Parser[ "containsInvalidLine=TRUE"
, ""
, "here"
, ""
, "# Commented line"
, "ENV=development"
]
|> String.join "\n"
|> Parser.run Envfile.parser
--> Err [ { col = 5, row = 4, problem = Parser.ExpectingSymbol "=" } ]
-- (No idea why row = 4, not 3!)
```### Encoding
```elm
import Dict
import Envfile[ ("this is not a valid variable name!", "so it won’t be included")
, ("thisIsThough", "So it will, and the newline will be escaped too\n!")
]
|> Dict.fromList
|> Envfile.encode
--> "thisIsThough=So it will, and the newline will be escaped too\\n!"```
```elm
import Dict
import Envfile[ ("MAGIC_NUMBER", "346")
, ("GREETING", "Hello world")
, ("API_KEY", "239847dflkjw34o87fjsdfkuy3dj")
]
|> Dict.fromList
|> Envfile.encode
|> String.lines
|> List.sort
--> [ "API_KEY=239847dflkjw34o87fjsdfkuy3dj"
--> , "GREETING=Hello world"
--> , "MAGIC_NUMBER=346"
--> ]
```