@leyyo/common 1.3.14 → 1.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/function/is-class.js +18 -7
- package/dist/sys/sys-stat.d.ts +78 -0
- package/dist/sys/sys-stat.js +20 -0
- package/package.json +1 -1
|
@@ -5,14 +5,25 @@
|
|
|
5
5
|
* @return {boolean} - is class?
|
|
6
6
|
* */
|
|
7
7
|
export function isClass(fn) {
|
|
8
|
-
|
|
9
|
-
if (!(fn && fn.constructor === Function) || fn.prototype === undefined) {
|
|
8
|
+
if (typeof fn !== 'function') {
|
|
10
9
|
return false;
|
|
11
10
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return true;
|
|
11
|
+
try {
|
|
12
|
+
return Function.prototype.toString.call(fn).toString().startsWith('class ');
|
|
15
13
|
}
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
catch (e) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
// // Class constructor is also a function
|
|
18
|
+
// if ( !(fn && fn.constructor === Function) || (fn as Fnc).prototype === undefined) {
|
|
19
|
+
// return false;
|
|
20
|
+
// }
|
|
21
|
+
//
|
|
22
|
+
// // This is a class that extends other class
|
|
23
|
+
// if (Function.prototype !== Object.getPrototypeOf(fn)) {
|
|
24
|
+
// return true;
|
|
25
|
+
// }
|
|
26
|
+
//
|
|
27
|
+
// // Usually a function will only have 'constructor' in the prototype
|
|
28
|
+
// return Object.getOwnPropertyNames((fn as Fnc).prototype).length > 1;
|
|
18
29
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export declare function sysStat(): SysStat;
|
|
2
|
+
export interface SysStat {
|
|
3
|
+
cpu: SysStatCpu;
|
|
4
|
+
memory: SysStatMemory;
|
|
5
|
+
time: SysStatTime;
|
|
6
|
+
npm: SysStatNpm;
|
|
7
|
+
node: SysStatNode;
|
|
8
|
+
project: SysStatProject;
|
|
9
|
+
os: SysStatOs;
|
|
10
|
+
}
|
|
11
|
+
export interface SysStatCpu {
|
|
12
|
+
user: number;
|
|
13
|
+
system: number;
|
|
14
|
+
}
|
|
15
|
+
export interface SysStatTime {
|
|
16
|
+
uptime: number;
|
|
17
|
+
startedAt: number;
|
|
18
|
+
}
|
|
19
|
+
export interface SysStatNpm {
|
|
20
|
+
pwd: string;
|
|
21
|
+
version: string;
|
|
22
|
+
}
|
|
23
|
+
export interface SysStatNode {
|
|
24
|
+
type: string;
|
|
25
|
+
version: string;
|
|
26
|
+
}
|
|
27
|
+
export interface SysStatProject {
|
|
28
|
+
name: string;
|
|
29
|
+
version: string;
|
|
30
|
+
environment: string;
|
|
31
|
+
log: string;
|
|
32
|
+
}
|
|
33
|
+
export interface SysStatOs {
|
|
34
|
+
version: string;
|
|
35
|
+
arch: string;
|
|
36
|
+
platform: string;
|
|
37
|
+
machineType: string;
|
|
38
|
+
network: Record<string, unknown>;
|
|
39
|
+
cpu: Array<SysStatCpuInfo>;
|
|
40
|
+
}
|
|
41
|
+
export interface SysStatMemory {
|
|
42
|
+
/**
|
|
43
|
+
* Resident Set Size, is the amount of space occupied in the main memory device (that is a subset of the total allocated memory) for the
|
|
44
|
+
* process, including all C++ and JavaScript objects and code.
|
|
45
|
+
*/
|
|
46
|
+
rss: number;
|
|
47
|
+
/**
|
|
48
|
+
* Refers to V8's memory usage.
|
|
49
|
+
*/
|
|
50
|
+
heapTotal: number;
|
|
51
|
+
/**
|
|
52
|
+
* Refers to V8's memory usage.
|
|
53
|
+
*/
|
|
54
|
+
heapUsed: number;
|
|
55
|
+
external: number;
|
|
56
|
+
/**
|
|
57
|
+
* Refers to memory allocated for `ArrayBuffer`s and `SharedArrayBuffer`s, including all Node.js Buffers. This is also included
|
|
58
|
+
* in the external value. When Node.js is used as an embedded library, this value may be `0` because allocations for `ArrayBuffer`s
|
|
59
|
+
* may not be tracked in that case.
|
|
60
|
+
*/
|
|
61
|
+
arrayBuffers: number;
|
|
62
|
+
}
|
|
63
|
+
export interface SysStatCpuInfo {
|
|
64
|
+
model: string;
|
|
65
|
+
speed: number;
|
|
66
|
+
times: {
|
|
67
|
+
/** The number of milliseconds the CPU has spent in user mode. */
|
|
68
|
+
user: number;
|
|
69
|
+
/** The number of milliseconds the CPU has spent in nice mode. */
|
|
70
|
+
nice: number;
|
|
71
|
+
/** The number of milliseconds the CPU has spent in sys mode. */
|
|
72
|
+
sys: number;
|
|
73
|
+
/** The number of milliseconds the CPU has spent in idle mode. */
|
|
74
|
+
idle: number;
|
|
75
|
+
/** The number of milliseconds the CPU has spent in irq mode. */
|
|
76
|
+
irq: number;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
export function sysStat() {
|
|
3
|
+
const uptime = Math.round(process.uptime() * 1_000);
|
|
4
|
+
return {
|
|
5
|
+
cpu: process.cpuUsage(),
|
|
6
|
+
memory: process.memoryUsage(),
|
|
7
|
+
time: { uptime, startedAt: Date.now() - uptime },
|
|
8
|
+
npm: { pwd: process.env.PWD, version: process.env.npm_config_npm_version },
|
|
9
|
+
node: { type: 'module', version: process.env.npm_config_node_version },
|
|
10
|
+
project: { name: process.env.npm_package_name, version: process.env.npm_package_version, environment: process.env.NODE_ENV, log: process.env.LOG_LEVEL },
|
|
11
|
+
os: {
|
|
12
|
+
version: os.version(),
|
|
13
|
+
arch: os.arch(),
|
|
14
|
+
platform: os.platform(),
|
|
15
|
+
machineType: os.machine(),
|
|
16
|
+
network: os.networkInterfaces(),
|
|
17
|
+
cpu: os.cpus(),
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|