sema-dotenv 0.1.0

Parse .env files and load environment variables

API reference 6 exports

Exported declarations from this release. Parameter names and descriptions come directly from its source.

dotenv/get

Source :104
(dotenv/get key . default)
Get an environment variable, falling back to default (nil when omitted).
View source definition
(define (dotenv/get key . default)
  "Get an environment variable, falling back to default (nil when omitted)."
  (let ((val (env key)))
    (if (nil? val)
      (if (null? default) nil (first default))
      val)))

dotenv/load

Source :85
(dotenv/load path . opts)
Read a .env file and set its variables in the process environment. Already-set env vars are NOT overridden unless {:override #t} is passed. Returns the full parsed map.
View source definition
(define (dotenv/load path . opts)
  "Read a .env file and set its variables in the process environment. Already-set env vars are NOT overridden unless {:override #t} is passed. Returns the full parsed map."
  (let* ((o (if (null? opts) {} (first opts)))
         (override (get o :override #f))
         (vars (dotenv/read path)))
    (for-each (fn (entry)
                (let ((k (first entry))
                      (v (nth entry 1)))
                  (when (or override (nil? (env k)))
                    (sys/set-env k v))))
              (map/entries vars))
    vars))

dotenv/load-if-exists

Source :98
(dotenv/load-if-exists path . opts)
Like dotenv/load, but returns {} instead of erroring when the file does not exist. Accepts the same {:override #t} option.
View source definition
(define (dotenv/load-if-exists path . opts)
  "Like dotenv/load, but returns {} instead of erroring when the file does not exist. Accepts the same {:override #t} option."
  (if (file/exists? path)
    (apply dotenv/load (cons path opts))
    (hash-map)))

dotenv/parse

Source :75
(dotenv/parse content)
Parse .env file contents into a {"KEY" "value"} map. Handles comments, export prefixes, quoted values, inline comments, and CRLF line endings; strips a leading UTF-8 BOM; malformed lines are skipped. When a key repeats, the last line wins.
View source definition
(define (dotenv/parse content)
  "Parse .env file contents into a {\"KEY\" \"value\"} map. Handles comments, export prefixes, quoted values, inline comments, and CRLF line endings; strips a leading UTF-8 BOM; malformed lines are skipped. When a key repeats, the last line wins."
  (map/from-entries
    (filter (fn (entry) (not (nil? entry)))
            (map parse-line (string/lines (strip-bom content))))))

dotenv/read

Source :81
(dotenv/read path)
Read and parse a .env file from disk into a map. Errors if the file does not exist.
View source definition
(define (dotenv/read path)
  "Read and parse a .env file from disk into a map. Errors if the file does not exist."
  (dotenv/parse (file/read path)))

dotenv/require

Source :111
(dotenv/require . required-keys)
Assert that every listed environment variable is set — errors naming the missing ones.
View source definition
(define (dotenv/require . required-keys)
  "Assert that every listed environment variable is set — errors naming the missing ones."
  (let ((missing (filter (fn (k) (nil? (env k))) required-keys)))
    (when (not (null? missing))
      (error (format "dotenv/require: missing required environment variables: ~a — set them or add them to your .env"
                     (string/join missing ", ")))))))
About this reference

Generated with sema-reader 1.37.0 without executing package code. These are source declarations; dynamic exports, aliases, and runtime changes are not inferred.

Archive SHA-256 c9b6a548684b2b7d73682984b8c7980dc2cc69597fd9ace82a142029dc7c57b8