MCPcopy Create free account
hub / github.com/effect-app/libs / parseDotEnvContents

Function parseDotEnvContents

repos/effect/packages/effect/src/ConfigProvider.ts:943–976  ·  view source on GitHub ↗
(lines: string)

Source from the content-addressed store, hash-verified

941
942function buildEnvTrie(env: Record<string, string | undefined>): EnvTrieNode {
943 const trie: EnvTrieNode = {}
944
945 for (const [name, value] of Object.entries(env)) {
946 if (value === undefined) continue
947
948 // Split on "_" and keep empty segments (no special handling for "__")
949 const segments = name.split("_")
950
951 let node = trie
952 for (const seg of segments) {
953 const children = node.children ??= Object.create(null)
954 node = children[seg] ??= {}
955 }
956 }
957
958 return trie
959}
960
961const NUMERIC_INDEX = /^(0|[1-9][0-9]*)$/
962
963function nodeAtEnv(
964 trie: EnvTrieNode,
965 env: Record<string, string | undefined>,
966 path: Path,
967 preserveEmptyStrings: boolean
968): Node | undefined {
969 const key = path.map(String).join("_")
970 const leafValue = emptyStringAsMissing(Object.hasOwn(env, key) ? env[key] : undefined, preserveEmptyStrings)
971
972 const trieNode = trieNodeAt(trie, path)
973 const children = trieNode?.children ? Object.keys(trieNode.children) : []
974
975 if (children.length === 0) {
976 return leafValue === undefined ? undefined : makeValue(leafValue)
977 }
978
979 const allNumeric = children.every((k) => NUMERIC_INDEX.test(k))

Callers 2

fromDotEnvContentsFunction · 0.85
ConfigProvider.tsFile · 0.85

Calls 2

execMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…