summaryrefslogtreecommitdiff
path: root/std/node/os.ts
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2020-02-23 20:40:44 +0100
committerGitHub <noreply@github.com>2020-02-23 14:40:44 -0500
commit45eb2f9b37c2c7498c58eb45f76667aaa4a7d731 (patch)
treeeb58ad114b496ede1223bd653236f18506cbb31d /std/node/os.ts
parentd9886a44d107de48b312ba71833709494b5ade5e (diff)
feat(std/node): add os Symbol.toPrimitive methods (#4073)
Node's os module exports a number of methods that evaluate to themselves when coerced to a primitive. I.e., `"" + os.arch` and `os.arch()` evaluate to the same string, and now Deno's shims do too.
Diffstat (limited to 'std/node/os.ts')
-rw-r--r--std/node/os.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/std/node/os.ts b/std/node/os.ts
index 51e5bbd93..39209b4b7 100644
--- a/std/node/os.ts
+++ b/std/node/os.ts
@@ -89,6 +89,17 @@ interface UserInfo {
homedir: string;
}
+arch[Symbol.toPrimitive] = (): string => arch();
+endianness[Symbol.toPrimitive] = (): string => endianness();
+freemem[Symbol.toPrimitive] = (): number => freemem();
+homedir[Symbol.toPrimitive] = (): string | null => homedir();
+hostname[Symbol.toPrimitive] = (): string | null => hostname();
+platform[Symbol.toPrimitive] = (): string => platform();
+release[Symbol.toPrimitive] = (): string => release();
+totalmem[Symbol.toPrimitive] = (): number => totalmem();
+type[Symbol.toPrimitive] = (): string => type();
+uptime[Symbol.toPrimitive] = (): number => uptime();
+
/** Returns the operating system CPU architecture for which the Deno binary was compiled */
export function arch(): string {
return Deno.build.arch;