1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-01 16:51:13 -05:00
denoland-deno/cli/js/ops/os.ts

46 lines
968 B
TypeScript
Raw Normal View History

2020-01-02 15:13:47 -05:00
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
2020-07-06 21:45:39 -04:00
import { sendSync } from "./dispatch_json.ts";
export function loadavg(): number[] {
2020-02-25 09:14:27 -05:00
return sendSync("op_loadavg");
}
2019-02-02 22:05:30 -05:00
2019-09-27 19:09:42 -04:00
export function hostname(): string {
2020-02-25 09:14:27 -05:00
return sendSync("op_hostname");
2019-09-27 19:09:42 -04:00
}
export function osRelease(): string {
2020-02-25 09:14:27 -05:00
return sendSync("op_os_release");
}
export function exit(code = 0): never {
2020-02-25 09:14:27 -05:00
sendSync("op_exit", { code });
throw new Error("Code not reachable");
}
function setEnv(key: string, value: string): void {
2020-02-25 09:14:27 -05:00
sendSync("op_set_env", { key, value });
}
function getEnv(key: string): string | undefined {
2020-02-25 09:14:27 -05:00
return sendSync("op_get_env", { key })[0];
}
function deleteEnv(key: string): void {
sendSync("op_delete_env", { key });
}
export const env = {
get: getEnv,
2020-07-06 21:45:39 -04:00
toObject(): Record<string, string> {
return sendSync("op_env");
},
set: setEnv,
delete: deleteEnv,
};
export function execPath(): string {
2020-02-25 09:14:27 -05:00
return sendSync("op_exec_path");
}