node-os-utils 1.0: Add types (#39408)

* node-os-utils 1.0: Add types

* apply library file layout

* fix lint errors
This commit is contained in:
Nasreddine Bac Ali
2019-10-25 22:26:23 +02:00
committed by Wesley Wigham
parent e2b59498db
commit dc97fa1c56
14 changed files with 202 additions and 0 deletions

6
types/node-os-utils/index.d.ts vendored Normal file
View File

@@ -0,0 +1,6 @@
// Type definitions for node-os-utils 1.0
// Project: https://github.com/SunilWang/node-os-utils
// Definitions by: Nasreddine Bac Ali <https://github.com/bacali95>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export * from './lib';

22
types/node-os-utils/lib/cpu.d.ts vendored Normal file
View File

@@ -0,0 +1,22 @@
export default class Cpu {
average(): CpuAverageInfo;
usage(interval?: number): Promise<number>;
free(interval?: number): Promise<number>;
count(): number;
model(): string;
loadavg(): number[];
loadavgTime(time: string | number): number;
}
export interface CpuAverageInfo {
totalIdle: number;
totalTick: number;
avgIdle: number;
avgTotal: number;
}

22
types/node-os-utils/lib/drive.d.ts vendored Normal file
View File

@@ -0,0 +1,22 @@
export default class Drive {
info(diskName: string): Promise<DriveInfo>;
free(diskName: string): Promise<DriveFreeInfo>;
used(diskName: string): Promise<DriveUsedInfo>;
}
export interface DriveFreeInfo {
totalGb: number;
freeGb: number;
freePercentage: number;
}
export interface DriveUsedInfo {
totalGb: number;
usedGb: number;
usedPercentage: number;
}
export interface DriveInfo extends DriveFreeInfo, DriveUsedInfo {
}

33
types/node-os-utils/lib/index.d.ts vendored Normal file
View File

@@ -0,0 +1,33 @@
import Cpu from './cpu';
import Drive from './drive';
import Mem from './mem';
import NetStat from './netstat';
import OpenFiles from './openfiles';
import Os from './os';
import OsCmd from './oscmd';
import Proc from './proc';
import Users from './users';
export const cpu: Cpu;
export const drive: Drive;
export const mem: Mem;
export const netstat: NetStat;
export const openfiles: OpenFiles;
export const os: Os;
export const oscmd: OsCmd;
export const proc: Proc;
export const users: Users;
export let options: { NOT_SUPPORTED_VALUE: string, INTERVAL: number };
export function exec(command: string): () => Promise<string>;
export * from './cpu';
export * from './drive';
export * from './mem';
export * from './netstat';
export * from './openfiles';
export * from './os';
export * from './oscmd';
export * from './proc';
export * from './users';

23
types/node-os-utils/lib/mem.d.ts vendored Normal file
View File

@@ -0,0 +1,23 @@
export default class Mem {
info(): Promise<MemInfo>;
free(): Promise<MemFreeInfo>;
used(): Promise<MemUsedInfo>;
totalMem(): number;
}
export interface MemFreeInfo {
totalMemMb: number;
freeMemMb: number;
}
export interface MemUsedInfo {
totalMemMb: number;
usedMemMb: number;
}
export interface MemInfo extends MemFreeInfo, MemUsedInfo {
freeMemPercentage: number;
}

17
types/node-os-utils/lib/netstat.d.ts vendored Normal file
View File

@@ -0,0 +1,17 @@
export default class NetStat {
stats(): Promise<NetStatInfo[]>;
inOut(interval?: number): Promise<NetStatMetrics | string>;
}
export interface NetStatInfo {
interface: string;
inputBytes: string;
outputBytes: string;
}
export interface NetStatMetrics {
total: { inputMb: number; outputMb: number; };
[key: string]: { inputMb: number; outputMb: number; };
}

View File

@@ -0,0 +1,3 @@
export default class OpenFiles {
openFd(): Promise<number>;
}

27
types/node-os-utils/lib/os.d.ts vendored Normal file
View File

@@ -0,0 +1,27 @@
export default class Os {
oos(): () => Promise<string>;
platform(): Platform;
uptime(): number;
ip(): string;
hostname(): string;
type(): string;
arch(): string;
}
type Platform = 'aix'
| 'android'
| 'darwin'
| 'freebsd'
| 'linux'
| 'openbsd'
| 'sunos'
| 'win32'
| 'cygwin';
export {};

12
types/node-os-utils/lib/oscmd.d.ts vendored Normal file
View File

@@ -0,0 +1,12 @@
export default class OsCmd {
topCpu(): () => Promise<string>;
topMem: () => Promise<string>;
vmstats: () => Promise<string>;
processesUsers: () => Promise<string>;
diskUsage: () => Promise<string>;
who: () => Promise<string>;
whoami: () => Promise<string>;
openPorts: () => Promise<string>;
ifconfig: () => Promise<string>;
}

5
types/node-os-utils/lib/proc.d.ts vendored Normal file
View File

@@ -0,0 +1,5 @@
export default class Proc {
totalProcesses(): Promise<number | string>;
zombieProcesses(): Promise<number | string>;
}

3
types/node-os-utils/lib/users.d.ts vendored Normal file
View File

@@ -0,0 +1,3 @@
export default class Users {
openedCount(): Promise<number | string>;
}

View File

@@ -0,0 +1,4 @@
import * as NodeOsUtils from 'node-os-utils';
NodeOsUtils.mem.info()
.then(console.log);

View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"node-os-utils-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }