Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 34 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { readFileSync } from "fs" |
||
2 | import { assigner, main, Reader } from "./main" |
||
3 | |||
4 | const {assign: $assign} = Object |
||
5 | |||
6 | export { parse } from "./parse" |
||
7 | export { argEnv } |
||
8 | export default argEnv |
||
9 | |||
10 | /** |
||
11 | * **NB!** args, package and ENV are already picked |
||
12 | * Revert precedence |
||
13 | * @param {string[]} paths |
||
14 | * @param {*} [env] `= process.env` |
||
15 | * @param {*} [target] `= {}` |
||
16 | * @param {*} [reader] `= readFileSync` |
||
17 | */ |
||
18 | // TODO #4 Like `path.unshift(".env")` |
||
19 | // TODO Move to a separate module |
||
20 | function argEnv<T extends Record<string, unknown>>(paths: string[], env = process.env, target = {} as T, reader = readFileSync as Reader) { |
||
21 | assigner(env, paths, reader, target) |
||
22 | $assign(env, target) |
||
23 | |||
24 | return target |
||
25 | } |
||
26 | |||
27 | main( |
||
28 | process.env, |
||
29 | process.argv, |
||
30 | readFileSync, |
||
31 | // TODO #7 |
||
32 | false |
||
33 | ) |
||
34 |