deno.land / x / lume@v2.1.4 / core / utils / env.ts

نووسراو ببینە
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
46
47
48
const envVars = new Map<string, string>();
export function setEnv(name: string, value: string) { // Deno Deploy doesn't support permissions.requestSync // https://github.com/denoland/deploy_feedback/issues/527 if (Deno.permissions.querySync?.({ name: "env" }).state === "granted") { Deno.env.set(name, value); } else { envVars.set(name, value); }}
export function env<T>(name: string): T | undefined { if (envVars.has(name)) { return envVars.get(name) as T; }
// Deno Deploy doesn't support permissions.requestSync // https://github.com/denoland/deploy_feedback/issues/527 const allowed = !Deno.permissions.requestSync || Deno.permissions.requestSync({ name: "env" }).state === "granted";
if (!allowed) { return undefined; }
const value = envVars.has(name) ? envVars.get(name) : Deno.env.get(name);
if (typeof value === "undefined") { return undefined; }
switch (value.toLowerCase()) { case "true": case "on": case "1": return true as T;
case "false": case "off": case "0": return false as T;
default: return value as T; }}
lume

Version Info

Tagged at
7 months ago