Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-environment

Environment files for Pudu: load .env variables safely with layered files, discovery, expansion, typed reads, and secrets kept out of every message

0.1.0Apache-2.01

InstallClose

Keys.pudu

Pudu29 lines1.0 KB

GitHub ↗
1/** @Domain.Keys.Module — field names to environment variable names */2module PuduLangEnvironment.Domain.Keys34import Std.Char as Char5import PuduLangEnvironment.Constants.Names as Names67/// The variable a field reads when no `@env` names one: the field's name in upper snake case,8/// with `_` before each upper-case letter that follows a lower-case letter or a digit.9export fn fromField(name: Str) -> Str {10  var pieces: Array[Str] = []11  var previous = ' '12  for symbol in name {13    if Char.isUpper(symbol) && (Char.isLower(previous) || Char.isDigit(previous)) { pieces = pieces.push("_") }14    pieces = pieces.push(Char.toUpper(symbol).toText())15    previous = symbol16  }17  pieces.join("")18}1920/// The variable a configuration setting reads: its key in upper case with each `.` and `-` as `_`,21/// the spelling the standard configuration reads from the environment.22export fn fromSetting(key: Str) -> Str {23  var pieces: Array[Str] = []24  for symbol in key {25    pieces = pieces.push(if Names.SETTING_SEPARATORS.contains(symbol) { "_" } else { Char.toUpper(symbol).toText() })26  }27  pieces.join("")28}29