From 7a9766dd18cc85053c984cb991dc3debac92530c Mon Sep 17 00:00:00 2001 From: MVEMCJSUNPE <2frac.d.x@gmail.com> Date: Tue, 15 Dec 2020 04:13:22 -0600 Subject: feat(std/node): Added os.type (#8591) --- std/node/os.ts | 13 +++++++++++-- std/node/os_test.ts | 14 +++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'std') diff --git a/std/node/os.ts b/std/node/os.ts index bec3de5ee..776eff92d 100644 --- a/std/node/os.ts +++ b/std/node/os.ts @@ -190,9 +190,18 @@ export function totalmem(): number { return Deno.systemMemoryInfo().total; } -/** Not yet implemented */ +/** Returns operating system type (i.e. 'Windows_NT', 'Linux', 'Darwin') */ export function type(): string { - notImplemented(SEE_GITHUB_ISSUE); + switch (Deno.build.os) { + case "windows": + return "Windows_NT"; + case "linux": + return "Linux"; + case "darwin": + return "Darwin"; + default: + throw Error("unreachable"); + } } /** Not yet implemented */ diff --git a/std/node/os_test.ts b/std/node/os_test.ts index 8879f8345..3200083a1 100644 --- a/std/node/os_test.ts +++ b/std/node/os_test.ts @@ -47,6 +47,13 @@ Deno.test({ }, }); +Deno.test({ + name: "type is a string", + fn() { + assertEquals(typeof os.type(), "string"); + }, +}); + Deno.test({ name: "getPriority(): PID must be a 32 bit integer", fn() { @@ -245,13 +252,6 @@ Deno.test({ Error, "Not implemented", ); - assertThrows( - () => { - os.type(); - }, - Error, - "Not implemented", - ); assertThrows( () => { os.uptime(); -- cgit v1.2.3