- Notifications
You must be signed in to change notification settings - Fork0
juri/dotenvy
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
DotEnvy is a dotenv file parser for Swift. It allows you to load values from an.env
file, similar to the librariesfornode.js,Python,Ruby,Rust1 etc.
DotEnvy supports multiline strings and variable substitution.
For more detailed syntax examples and API documentation visit DotEnvy'sdocumentation on Swift Package Index.
The dotenv format does not have a specification, but this library supports the common features. The syntaxresembles Bash. Examples:
KEY=valueKEY2 ="quoted value" KEY3= unquoted value"with" quotes inside# commentKEY4 ='quoted value referring to ${KEY3}'# trailing commentKEY5=unquoted value referring to${KEY4}KEY6="multilinestring"
DotEnvy has helpful error reporting on syntax errors.
letsource=#"""KEY="VALUE"""#do{ _=tryDotEnvironment.parse(string: source)}catchlet error asParseErrorWithLocation{letformatted= error.formatError(source: source)print(formatted)}
outputs
1: KEY="VALUE ^Error on line 1: Unterminated quote
There's also a command line tool,dotenv-tool
. It supports checking dotenv files for syntax errors and convertingthem to JSON. To install, run:
swift build -c releasecp .build/release/dotenv-tool /usr/local/bin
Footnotes
I accidentally used the same name they use; apologies!↩
About
DotEnv handling for Swift
Topics
Resources
License
Stars
Watchers
Forks
Packages0
No packages published