mirror of
https://github.com/denoland/deno.git
synced 2024-11-23 15:16:54 -05:00
Remove os.userHomeDir in favor of Deno.homeDir (denoland/deno_std#523)
Original: 88b4894579
This commit is contained in:
parent
9a01d6455e
commit
c08a27de9a
4 changed files with 0 additions and 51 deletions
16
os/README.md
16
os/README.md
|
@ -1,16 +0,0 @@
|
|||
# os
|
||||
|
||||
Module provide platform-independent interface to operating system functionality.
|
||||
|
||||
## Usage
|
||||
|
||||
### userHomeDir
|
||||
|
||||
Returns the current user's home directory. On Unix, including macOS, it returns the \$HOME environment variable. On Windows, it returns %USERPROFILE%.
|
||||
Needs permissions to access env (--allow-env).
|
||||
|
||||
```ts
|
||||
import { userHomeDir } from "https://deno.land/std/os/mod.ts";
|
||||
|
||||
userHomeDir();
|
||||
```
|
26
os/mod.ts
26
os/mod.ts
|
@ -1,26 +0,0 @@
|
|||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
/**
|
||||
* Returns the current user's home directory.
|
||||
* On Unix, including macOS, it returns the $HOME environment variable.
|
||||
* On Windows, it returns %USERPROFILE%.
|
||||
* Needs permissions to access env (--allow-env).
|
||||
*
|
||||
* Ported from Go: https://github.com/golang/go/blob/go1.12.5/src/os/file.go#L389
|
||||
*/
|
||||
export function userHomeDir(): string {
|
||||
let env = "HOME";
|
||||
let envErr = "$HOME";
|
||||
|
||||
if (Deno.platform.os === "win") {
|
||||
env = "USERPROFILE";
|
||||
envErr = "%USERPROFILE%";
|
||||
}
|
||||
|
||||
const value = Deno.env()[env];
|
||||
if (value !== "") {
|
||||
return value;
|
||||
}
|
||||
|
||||
throw new Error(`Environment variable '${envErr}' is not defined.`);
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
import { test } from "../testing/mod.ts";
|
||||
import { assertNotEquals } from "../testing/asserts.ts";
|
||||
import { userHomeDir } from "./mod.ts";
|
||||
|
||||
test(function testUserHomeDir(): void {
|
||||
assertNotEquals(userHomeDir(), "");
|
||||
});
|
1
test.ts
1
test.ts
|
@ -24,7 +24,6 @@ import "./util/test.ts";
|
|||
import "./uuid/test.ts";
|
||||
import "./ws/test.ts";
|
||||
import "./encoding/test.ts";
|
||||
import "./os/test.ts";
|
||||
|
||||
import { xrun } from "./prettier/util.ts";
|
||||
import { red, green } from "./colors/mod.ts";
|
||||
|
|
Loading…
Reference in a new issue