feat: Add support for passing a key to Deno.env() (#2952)

This adds a new op to get a single env var.
This commit is contained in:
Jed Fox 2019-10-02 11:55:28 -04:00 committed by Ryan Dahl
parent c920c5f62a
commit 99eec73b4b
7 changed files with 144 additions and 9 deletions

View file

@ -44,6 +44,16 @@ declare namespace Deno {
export function env(): {
[index: string]: string;
};
/** Returns the value of an environment variable at invocation.
* If the variable is not present, `undefined` will be returned.
*
* const myEnv = Deno.env();
* console.log(myEnv.SHELL);
* myEnv.TEST_VAR = "HELLO";
* const newEnv = Deno.env();
* console.log(myEnv.TEST_VAR == newEnv.TEST_VAR);
*/
export function env(key: string): string | undefined;
/**
* Returns the current user's home directory.
* Requires the `--allow-env` flag.