EnvParser class

Parses dotenv (.env) style files into a Map<String, dynamic>.

Supported features

  • UTF-8 BOM removal.
  • Normalization of line endings (\r\n / \r\n).
  • Blank line and comment (# or ;) skipping.
  • export prefix (e.g. export KEY=VALUE).
  • Key validation: must match ^[A-Za-z_][A-Za-z0-9_.-]*$.
  • Key/value delimiters: = or : (outside of quotes).
  • Quoted values:
    • Single-quoted → literal except \' and \\.
    • Double-quoted → supports \n, \r, \t, \", \', \\.
    • Multi-line quoted values are supported.
  • Unquoted values:
    • Strips inline comments after # or ;.
    • Supports escaping comment markers and spaces with \.

Example

# standard
HOST=localhost
PORT=8080

# quoted
PASSWORD="p@ss word"

# multi-line
CERT="-----BEGIN-----
some-data
-----END-----"

Produces:

{
  'HOST': 'localhost',
  'PORT': '8080',
  'PASSWORD': 'p@ss word',
  'CERT': '-----BEGIN-----\nsome-data\n-----END-----'
}
Inheritance

Constructors

EnvParser()
Create an EnvParser.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
parse(String source) Map<String, dynamic>
Parses the given source string into a Map<String, dynamic>.
override
parseAs(Asset asset) Object
Parses the given Asset and returns it as a generic Object.
inherited
parseAsset(Asset asset) Map<String, dynamic>
Parses a Jetleaf Asset into a Map<String, dynamic>.
override
parseFile(String path) Map<String, dynamic>
Optionally parses configuration directly from a file located at path.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited