mirror of
https://github.com/denoland/deno.git
synced 2025-01-11 00:21:05 -05:00
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.
This commit is contained in:
parent
d9886a44d1
commit
45eb2f9b37
2 changed files with 22 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -174,6 +174,17 @@ test({
|
|||
}
|
||||
});
|
||||
|
||||
test({
|
||||
name: "Primitive coercion works as expected",
|
||||
fn() {
|
||||
assertEquals(`${os.arch}`, os.arch());
|
||||
assertEquals(`${os.endianness}`, os.endianness());
|
||||
assertEquals(`${os.homedir}`, os.homedir());
|
||||
assertEquals(`${os.hostname}`, os.hostname());
|
||||
assertEquals(`${os.platform}`, os.platform());
|
||||
}
|
||||
});
|
||||
|
||||
test({
|
||||
name: "APIs not yet implemented",
|
||||
fn() {
|
||||
|
|
Loading…
Reference in a new issue