MCPcopy Create free account
hub / github.com/Effect-TS/effect / nodeAtEnv

Function nodeAtEnv

packages/effect/src/ConfigProvider.ts:963–986  ·  view source on GitHub ↗
(
  trie: EnvTrieNode,
  env: Record<string, string | undefined>,
  path: Path,
  preserveEmptyStrings: boolean
)

Source from the content-addressed store, hash-verified

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))
980 if (allNumeric) {
981 const length = Math.max(...children.map((k) => parseInt(k, 10))) + 1
982 return makeArray(length, leafValue)
983 }
984
985 return makeRecord(new Set(children), leafValue)
986}
987
988function trieNodeAt(root: EnvTrieNode, path: Path): EnvTrieNode | undefined {
989 if (path.length === 0) return root

Callers 1

fromEnvRecordFunction · 0.85

Calls 7

emptyStringAsMissingFunction · 0.85
trieNodeAtFunction · 0.85
makeValueFunction · 0.85
makeArrayFunction · 0.85
makeRecordFunction · 0.85
joinMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected