EnvParser constructor

EnvParser()

Create an EnvParser.

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-----'
}

Implementation

EnvParser();