mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 18:38:33 +00:00
BREAKING: Map-like interface for Deno.env (#4942)
This commit is contained in:
parent
17cf2ecdac
commit
721a4ad59d
9 changed files with 53 additions and 58 deletions
|
@ -27,22 +27,13 @@ function getEnv(key: string): string | undefined {
|
|||
return sendSync("op_get_env", { key })[0];
|
||||
}
|
||||
|
||||
export function env(): { [index: string]: string };
|
||||
export function env(key: string): string | undefined;
|
||||
export function env(
|
||||
key?: string
|
||||
): { [index: string]: string } | string | undefined {
|
||||
if (key) {
|
||||
return getEnv(key);
|
||||
}
|
||||
const env = sendSync("op_env");
|
||||
return new Proxy(env, {
|
||||
set(obj, prop: string, value: string): boolean {
|
||||
setEnv(prop, value);
|
||||
return Reflect.set(obj, prop, value);
|
||||
},
|
||||
});
|
||||
}
|
||||
export const env = {
|
||||
get: getEnv,
|
||||
toObject(): { [key: string]: string } {
|
||||
return sendSync("op_env");
|
||||
},
|
||||
set: setEnv,
|
||||
};
|
||||
|
||||
type DirKind =
|
||||
| "home"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue