diff options
author | Evgeniy Karagodin <ekaragodin@gmail.com> | 2019-06-25 23:05:41 +0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-06-25 09:05:41 -0700 |
commit | d089f9797830a2729cbd45cb4ea6312eb43a28de (patch) | |
tree | bf58f68b145696dc59282725b94dbfa8971a0e2c /js/os.ts | |
parent | c56df45355c8e68eabbfa62021e7ca7484115c0b (diff) |
Add homeDir to Deno namespace (#2578)
Diffstat (limited to 'js/os.ts')
-rw-r--r-- | js/os.ts | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -130,3 +130,23 @@ export function start(source?: string): msg.StartRes { return startResMsg; } + +/** + * Returns the current user's home directory. + * Does not require elevated privileges. + */ +export function homeDir(): string { + const builder = flatbuffers.createBuilder(); + const inner = msg.HomeDir.createHomeDir(builder); + const baseRes = sendSync(builder, msg.Any.HomeDir, inner)!; + assert(msg.Any.HomeDirRes === baseRes.innerType()); + const res = new msg.HomeDirRes(); + assert(baseRes.inner(res) != null); + const path = res.path(); + + if (!path) { + throw new Error("Could not get home directory."); + } + + return path; +} |