mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
feat(node-portscanner): add typings for portscanner (#16963)
This commit is contained in:
committed by
Mohamed Hegazy
parent
d191ea77f9
commit
2d60eb9964
56
types/node-portscanner/index.d.ts
vendored
Normal file
56
types/node-portscanner/index.d.ts
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
// Type definitions for portscanner 2.1
|
||||
// Project: https://github.com/baalexander/node-portscanner
|
||||
// Definitions by: Douglas Duteil <https://github.com/douglasduteil>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare module 'portscanner' {
|
||||
type Status = 'open' | 'closed';
|
||||
|
||||
type PortCallback = (error: Error | null, port: number) => void;
|
||||
type StatusCallback = (error: Error | null, port: Status) => void;
|
||||
|
||||
interface Options {
|
||||
host?: string;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
function checkPortStatus(port: number): Promise<Status>;
|
||||
|
||||
function checkPortStatus(port: number, host: string): Promise<Status>;
|
||||
function checkPortStatus(port: number, opts: Options): Promise<Status>;
|
||||
function checkPortStatus(port: number, checkPortCallback: StatusCallback): void;
|
||||
|
||||
function checkPortStatus(port: number, host: string, opts: Options): Promise<Status>;
|
||||
function checkPortStatus(port: number, host: string, checkPortCallback: StatusCallback): void;
|
||||
function checkPortStatus(port: number, opts: Options, checkPortCallback: StatusCallback): void;
|
||||
|
||||
function checkPortStatus(port: number, host: string, opts: Options, checkPortCallback: StatusCallback): void;
|
||||
|
||||
function findAPortNotInUse(portList: number[]): Promise<number>;
|
||||
function findAPortNotInUse(startPort: number): Promise<number>;
|
||||
|
||||
function findAPortNotInUse(portList: number[], findPortCallback: PortCallback): void;
|
||||
function findAPortNotInUse(portList: number[], host: string): Promise<number>;
|
||||
function findAPortNotInUse(startPort: number, findPortCallback: PortCallback): void;
|
||||
function findAPortNotInUse(startPort: number, host: string): Promise<number>;
|
||||
function findAPortNotInUse(startPort: number, endPort: number): Promise<number>;
|
||||
|
||||
function findAPortNotInUse(startPort: number, endPort: number, host: string): Promise<number>;
|
||||
function findAPortNotInUse(startPort: number, endPort: number, findPortCallback: PortCallback): void;
|
||||
|
||||
function findAPortNotInUse(startPort: number, endPort: number, host: string, findPortCallback: PortCallback): void;
|
||||
|
||||
function findAPortInUse(portList: number[]): Promise<number>;
|
||||
function findAPortInUse(startPort: number): Promise<number>;
|
||||
|
||||
function findAPortInUse(portList: number[], findPortCallback: PortCallback): void;
|
||||
function findAPortInUse(portList: number[], host: string): Promise<number>;
|
||||
function findAPortInUse(startPort: number, findPortCallback: PortCallback): void;
|
||||
function findAPortInUse(startPort: number, host: string): Promise<number>;
|
||||
function findAPortInUse(startPort: number, endPort: number): Promise<number>;
|
||||
|
||||
function findAPortInUse(startPort: number, endPort: number, host: string): Promise<number>;
|
||||
function findAPortInUse(startPort: number, endPort: number, findPortCallback: PortCallback): void;
|
||||
|
||||
function findAPortInUse(startPort: number, endPort: number, host: string, findPortCallback: PortCallback): void;
|
||||
}
|
||||
79
types/node-portscanner/node-portscanner-tests.ts
Normal file
79
types/node-portscanner/node-portscanner-tests.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as portscanner from 'portscanner';
|
||||
|
||||
import * as assert from 'assert';
|
||||
|
||||
const checkPortCallback = (error: Error | null, status: portscanner.Status) => {
|
||||
assert(error === null);
|
||||
error && assert(error.message === '');
|
||||
assert(status === 'open');
|
||||
assert(status === 'closed');
|
||||
};
|
||||
|
||||
const assertStatus = (status: portscanner.Status) => {
|
||||
assert(status === 'open');
|
||||
assert(status === 'closed');
|
||||
};
|
||||
|
||||
portscanner.checkPortStatus(3000).then(assertStatus);
|
||||
|
||||
portscanner.checkPortStatus(3000, '127.0.0.1').then(assertStatus);
|
||||
portscanner.checkPortStatus(3000, { host: '127.0.0.1' }).then(assertStatus);
|
||||
portscanner.checkPortStatus(3000, { timeout: 400 }).then(assertStatus);
|
||||
portscanner.checkPortStatus(3000, checkPortCallback);
|
||||
|
||||
portscanner.checkPortStatus(3000, { host: '127.0.0.1' }, checkPortCallback);
|
||||
portscanner.checkPortStatus(3000, { timeout: 400 }, checkPortCallback);
|
||||
portscanner.checkPortStatus(3000, '127.0.0.1', checkPortCallback);
|
||||
|
||||
portscanner.checkPortStatus(3000, '127.0.0.1', { timeout: 400 }).then(assertStatus);
|
||||
portscanner.checkPortStatus(3000, '127.0.0.1', { timeout: 400 }, checkPortCallback);
|
||||
|
||||
const findPortCallback = (error: Error | null, port: number) => {
|
||||
assert(error === null);
|
||||
error && assert(error.message === '');
|
||||
assert(port === 3005);
|
||||
};
|
||||
|
||||
const assertPort = (port: number) => {
|
||||
assert(port === 3005);
|
||||
};
|
||||
|
||||
// one argument
|
||||
portscanner.findAPortNotInUse([3000, 3005, 3006]).then(assertPort);
|
||||
portscanner.findAPortNotInUse(3000).then(assertPort);
|
||||
|
||||
// two arguments
|
||||
portscanner.findAPortNotInUse([3000, 3005, 3006], findPortCallback);
|
||||
portscanner.findAPortNotInUse([3000, 3005, 3006], '127.0.0.1').then(assertPort);
|
||||
|
||||
portscanner.findAPortNotInUse(3000, findPortCallback);
|
||||
portscanner.findAPortNotInUse(3000, '127.0.0.1').then(assertPort);
|
||||
portscanner.findAPortNotInUse(3000, 3010).then(assertPort);
|
||||
|
||||
// three arguments
|
||||
portscanner.findAPortNotInUse(3000, 3010, '127.0.0.1').then(assertPort);
|
||||
portscanner.findAPortNotInUse(3000, 3010, findPortCallback);
|
||||
|
||||
// four argumentss
|
||||
portscanner.findAPortNotInUse(3000, 3010, '127.0.0.1', findPortCallback);
|
||||
|
||||
// one argument
|
||||
portscanner.findAPortInUse([3000, 3005, 3006]).then(assertPort);
|
||||
portscanner.findAPortInUse(3000).then(assertPort);
|
||||
|
||||
// two arguments
|
||||
portscanner.findAPortInUse([3000, 3005, 3006], findPortCallback);
|
||||
portscanner.findAPortInUse([3000, 3005, 3006], '127.0.0.1').then(assertPort);
|
||||
|
||||
portscanner.findAPortInUse(3000, findPortCallback);
|
||||
portscanner.findAPortInUse(3000, '127.0.0.1').then(assertPort);
|
||||
portscanner.findAPortInUse(3000, 3010).then(assertPort);
|
||||
|
||||
// three arguments
|
||||
portscanner.findAPortInUse(3000, 3010, '127.0.0.1').then(assertPort);
|
||||
portscanner.findAPortInUse(3000, 3010, findPortCallback);
|
||||
|
||||
// four argumentss
|
||||
portscanner.findAPortInUse(3000, 3010, '127.0.0.1', findPortCallback);
|
||||
22
types/node-portscanner/tsconfig.json
Normal file
22
types/node-portscanner/tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"node-portscanner-tests.ts"
|
||||
]
|
||||
}
|
||||
7
types/node-portscanner/tslint.json
Normal file
7
types/node-portscanner/tslint.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-single-declare-module": false,
|
||||
"unified-signatures": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user