( trie: EnvTrieNode, env: Record<string, string | undefined>, path: Path, preserveEmptyStrings: boolean )
| 961 | const NUMERIC_INDEX = /^(0|[1-9][0-9]*)$/ |
| 962 | |
| 963 | function 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 | |
| 988 | function trieNodeAt(root: EnvTrieNode, path: Path): EnvTrieNode | undefined { |
| 989 | if (path.length === 0) return root |
no test coverage detected