-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathenv.ts
More file actions
41 lines (37 loc) · 977 Bytes
/
env.ts
File metadata and controls
41 lines (37 loc) · 977 Bytes
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
const _envShim = Object.create(null);
export type EnvObject = Record<string, string | undefined>;
const _getEnv = (useShim?: boolean) =>
globalThis.process?.env ||
import.meta.env ||
globalThis.Deno?.env.toObject() ||
globalThis.__env__ ||
(useShim ? _envShim : globalThis);
export const env = new Proxy<EnvObject>(_envShim, {
get(_, prop) {
const env = _getEnv();
return env[prop as any] ?? _envShim[prop];
},
has(_, prop) {
const env = _getEnv();
return prop in env || prop in _envShim;
},
set(_, prop, value) {
const env = _getEnv(true);
env[prop as any] = value;
return true;
},
deleteProperty(_, prop) {
if (!prop) {
return false;
}
const env = _getEnv(true);
delete env[prop as any];
return true;
},
ownKeys() {
const env = _getEnv(true);
return Object.keys(env);
},
});
export const nodeENV =
(typeof process !== "undefined" && process.env && process.env.NODE_ENV) || "";