( trie: EnvTrieNode, env: Record<string, string | undefined>, path: Path, preserveEmptyStrings: boolean )
| 996 | } |
| 997 | |
| 998 | function nodeAtEnv( |
| 999 | trie: EnvTrieNode, |
| 1000 | env: Record<string, string | undefined>, |
| 1001 | path: Path, |
| 1002 | preserveEmptyStrings: boolean |
| 1003 | ): Node | undefined { |
| 1004 | const key = path.map(String).join("_") |
| 1005 | const leafValue = emptyStringAsMissing(Object.hasOwn(env, key) ? env[key] : undefined, preserveEmptyStrings) |
| 1006 | |
| 1007 | const trieNode = trieNodeAt(trie, path) |
| 1008 | const children = trieNode?.children ? Object.keys(trieNode.children) : [] |
| 1009 | |
| 1010 | if (children.length === 0) { |
| 1011 | return leafValue === undefined ? undefined : makeValue(leafValue) |
| 1012 | } |
| 1013 | |
| 1014 | const allNumeric = children.every(Arr.isCanonicalArrayIndex) |
| 1015 | if (allNumeric) { |
| 1016 | const length = Math.max(...children.map((k) => parseInt(k, 10))) + 1 |
| 1017 | return makeArray(length, leafValue) |
| 1018 | } |
| 1019 | |
| 1020 | return makeRecord(new Set(children), leafValue) |
| 1021 | } |
| 1022 | |
| 1023 | function trieNodeAt(root: EnvTrieNode, path: Path): EnvTrieNode | undefined { |
| 1024 | if (path.length === 0) return root |
no test coverage detected