@std/data/config.ms#
Import each required symbol with import Name from "@std/data/config.ms".
parse_dotenv Function#
Parses .env text into a map in file order, without touching the process environment.
Use it to layer settings: read the file, then let real variables win, values.add(name, value).
To load a file straight into the environment use load_environment from @std/os/env.ms, which accepts the same syntax.
- Blank lines and
#comment lines are skipped; a leading byte-order mark is ignored. export NAME=valueis accepted, and a name is letters, digits and_, not starting with a digit.- A bare value ends at an inline
# comment(a#after a space or tab, or first) and is trimmed, soa#bis the valuea#b. A single-, double- or backtick-quoted value is literal, may span lines, and keeps any#. - Only text after a closing quote may be a comment. A later duplicate name replaces the earlier value and keeps its first position. Malformed lines (no
=, an invalid name, an unterminated quote, text after a closing quote) return anErrorwith kindEBADMSGand the line number indetails.
Example: parse_dotenv("PORT=8080\nNAME='my app' # label") holds PORT as "8080" and NAME as "my app".
Manuscript
fn parse_dotenv(text String) Result[Map[String, String], Error] { ... }parse_ini Function#
Parses INI text into sections of settings, both in file order. Keys before the first [section] header go in the section named "".
[name]starts a section; a repeated header continues the earlier one. Names and keys are trimmed.key = valueandkey: valueboth assign; the first=or:splits, so values may contain the other.- Lines starting with
#or;are comments, and so is text after#or;in a value. A value wrapped in matching"or'keeps such text and loses the quotes. - A later duplicate key in a section replaces the earlier value. A line without
=or:, or an unterminated[sectionheader, returns anErrorwith kindEBADMSGand the line number indetails.
Example: parse_ini("[db]\nhost = localhost\nport: 5432") holds ini["db"]["port"] as "5432".
Manuscript
fn parse_ini(text String) Result[Map[String, Map[String, String]], Error] { ... }