-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (38 loc) · 1.03 KB
/
Copy pathindex.js
File metadata and controls
45 lines (38 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { NativeModules } from 'react-native'
/**
* Loading environment variables from specified reference file and extending
* process environment variables, optionably possible to turn it off
* @param {String} environment file name without extension, it will be
* specified by platform
* @param {Boolean} extend process.env or not, default ture
* @return {Promise}
*/
export async function loadConfig (reference = '.env', extendProcess = true) {
const env = await NativeModules.RNDotEnv.load(reference)
if (extendProcess) {
process.env = {
...process.env,
...env
}
}
return env
}
/**
* Loading .env secure credentials to process environment
* @return {Object} environment variables
*/
export default function () {
const module = NativeModules.RNDotEnv
let env = {}
for (const key of Object.keys(module)) {
if (typeof module[key] !== "function") {
env[key] = module[key]
}
}
// extending process.env
process.env = {
...process.env,
...env
}
return env
}