-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathnode.ts
35 lines (33 loc) · 800 Bytes
/
node.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//================================================================
/**
* @packageDocumentation
* @module std
*/
//================================================================
/**
* Test whether the code is running on NodeJS.
*
* @return Whether NodeJS or not.
*/
export function is_node(): boolean {
if (is_node_ === null)
is_node_ = typeof global === "object" && is_node_process(global);
return is_node_;
}
/**
* @internal
*/
function is_node_process(m: typeof global | null): boolean {
return (
m !== null &&
typeof m.process === "object" &&
m.process !== null &&
typeof m.process.versions === "object" &&
m.process.versions !== null &&
typeof m.process.versions.node !== "undefined"
);
}
/**
* @internal
*/
let is_node_: boolean | null = null;