From 3afcde1e630ee329b7dacbbe68667576495d653e Mon Sep 17 00:00:00 2001 From: Douglas Duteil Date: Fri, 28 Jul 2017 16:14:34 +0200 Subject: [PATCH] refacto(portscanner): rename node-portscanner to match npm package name (#18465) --- types/node-portscanner/index.d.ts | 56 -------------- .../node-portscanner-tests.ts | 76 ------------------ types/portscanner/index.d.ts | 54 +++++++++++++ types/portscanner/portscanner-tests.ts | 77 +++++++++++++++++++ .../tsconfig.json | 2 +- .../tslint.json | 0 6 files changed, 132 insertions(+), 133 deletions(-) delete mode 100644 types/node-portscanner/index.d.ts delete mode 100644 types/node-portscanner/node-portscanner-tests.ts create mode 100644 types/portscanner/index.d.ts create mode 100644 types/portscanner/portscanner-tests.ts rename types/{node-portscanner => portscanner}/tsconfig.json (92%) rename types/{node-portscanner => portscanner}/tslint.json (100%) diff --git a/types/node-portscanner/index.d.ts b/types/node-portscanner/index.d.ts deleted file mode 100644 index 1993a2353c..0000000000 --- a/types/node-portscanner/index.d.ts +++ /dev/null @@ -1,56 +0,0 @@ -// Type definitions for portscanner 2.1 -// Project: https://github.com/baalexander/node-portscanner -// Definitions by: Douglas Duteil -// 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; - - function checkPortStatus(port: number, host: string): Promise; - function checkPortStatus(port: number, opts: Options): Promise; - function checkPortStatus(port: number, checkPortCallback: StatusCallback): void; - - function checkPortStatus(port: number, host: string, opts: Options): Promise; - 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; - function findAPortNotInUse(startPort: number): Promise; - - function findAPortNotInUse(portList: number[], findPortCallback: PortCallback): void; - function findAPortNotInUse(portList: number[], host: string): Promise; - function findAPortNotInUse(startPort: number, findPortCallback: PortCallback): void; - function findAPortNotInUse(startPort: number, host: string): Promise; - function findAPortNotInUse(startPort: number, endPort: number): Promise; - - function findAPortNotInUse(startPort: number, endPort: number, host: string): Promise; - 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; - function findAPortInUse(startPort: number): Promise; - - function findAPortInUse(portList: number[], findPortCallback: PortCallback): void; - function findAPortInUse(portList: number[], host: string): Promise; - function findAPortInUse(startPort: number, findPortCallback: PortCallback): void; - function findAPortInUse(startPort: number, host: string): Promise; - function findAPortInUse(startPort: number, endPort: number): Promise; - - function findAPortInUse(startPort: number, endPort: number, host: string): Promise; - function findAPortInUse(startPort: number, endPort: number, findPortCallback: PortCallback): void; - - function findAPortInUse(startPort: number, endPort: number, host: string, findPortCallback: PortCallback): void; -} diff --git a/types/node-portscanner/node-portscanner-tests.ts b/types/node-portscanner/node-portscanner-tests.ts deleted file mode 100644 index 3eb4243e86..0000000000 --- a/types/node-portscanner/node-portscanner-tests.ts +++ /dev/null @@ -1,76 +0,0 @@ -import * as portscanner from 'portscanner'; -declare function assert(cond: boolean): void; - -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); diff --git a/types/portscanner/index.d.ts b/types/portscanner/index.d.ts new file mode 100644 index 0000000000..6f80c5c66e --- /dev/null +++ b/types/portscanner/index.d.ts @@ -0,0 +1,54 @@ +// Type definitions for portscanner 2.1 +// Project: https://github.com/baalexander/node-portscanner +// Definitions by: Douglas Duteil +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export type Status = 'open' | 'closed'; + +export type PortCallback = (error: Error | null, port: number) => void; +export type StatusCallback = (error: Error | null, port: Status) => void; + +export interface Options { + host?: string; + timeout?: number; +} + +export function checkPortStatus(port: number): Promise; + +export function checkPortStatus(port: number, host: string): Promise; +export function checkPortStatus(port: number, opts: Options): Promise; +export function checkPortStatus(port: number, checkPortCallback: StatusCallback): void; + +export function checkPortStatus(port: number, host: string, opts: Options): Promise; +export function checkPortStatus(port: number, host: string, checkPortCallback: StatusCallback): void; +export function checkPortStatus(port: number, opts: Options, checkPortCallback: StatusCallback): void; + +export function checkPortStatus(port: number, host: string, opts: Options, checkPortCallback: StatusCallback): void; + +export function findAPortNotInUse(portList: number[]): Promise; +export function findAPortNotInUse(startPort: number): Promise; + +export function findAPortNotInUse(portList: number[], findPortCallback: PortCallback): void; +export function findAPortNotInUse(portList: number[], host: string): Promise; +export function findAPortNotInUse(startPort: number, findPortCallback: PortCallback): void; +export function findAPortNotInUse(startPort: number, host: string): Promise; +export function findAPortNotInUse(startPort: number, endPort: number): Promise; + +export function findAPortNotInUse(startPort: number, endPort: number, host: string): Promise; +export function findAPortNotInUse(startPort: number, endPort: number, findPortCallback: PortCallback): void; + +export function findAPortNotInUse(startPort: number, endPort: number, host: string, findPortCallback: PortCallback): void; + +export function findAPortInUse(portList: number[]): Promise; +export function findAPortInUse(startPort: number): Promise; + +export function findAPortInUse(portList: number[], findPortCallback: PortCallback): void; +export function findAPortInUse(portList: number[], host: string): Promise; +export function findAPortInUse(startPort: number, findPortCallback: PortCallback): void; +export function findAPortInUse(startPort: number, host: string): Promise; +export function findAPortInUse(startPort: number, endPort: number): Promise; + +export function findAPortInUse(startPort: number, endPort: number, host: string): Promise; +export function findAPortInUse(startPort: number, endPort: number, findPortCallback: PortCallback): void; + +export function findAPortInUse(startPort: number, endPort: number, host: string, findPortCallback: PortCallback): void; diff --git a/types/portscanner/portscanner-tests.ts b/types/portscanner/portscanner-tests.ts new file mode 100644 index 0000000000..a907e86d2a --- /dev/null +++ b/types/portscanner/portscanner-tests.ts @@ -0,0 +1,77 @@ +import { checkPortStatus, findAPortNotInUse, findAPortInUse, Status } from 'portscanner'; + +declare function assert(cond: boolean): void; + +const checkPortCallback = (error: Error | null, status: Status) => { + assert(error === null); + error && assert(error.message === ''); + assert(status === 'open'); + assert(status === 'closed'); +}; + +const assertStatus = (status: Status) => { + assert(status === 'open'); + assert(status === 'closed'); +}; + +checkPortStatus(3000).then(assertStatus); + +checkPortStatus(3000, '127.0.0.1').then(assertStatus); +checkPortStatus(3000, { host: '127.0.0.1' }).then(assertStatus); +checkPortStatus(3000, { timeout: 400 }).then(assertStatus); +checkPortStatus(3000, checkPortCallback); + +checkPortStatus(3000, { host: '127.0.0.1' }, checkPortCallback); +checkPortStatus(3000, { timeout: 400 }, checkPortCallback); +checkPortStatus(3000, '127.0.0.1', checkPortCallback); + +checkPortStatus(3000, '127.0.0.1', { timeout: 400 }).then(assertStatus); +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 +findAPortNotInUse([3000, 3005, 3006]).then(assertPort); +findAPortNotInUse(3000).then(assertPort); + +// two arguments +findAPortNotInUse([3000, 3005, 3006], findPortCallback); +findAPortNotInUse([3000, 3005, 3006], '127.0.0.1').then(assertPort); + +findAPortNotInUse(3000, findPortCallback); +findAPortNotInUse(3000, '127.0.0.1').then(assertPort); +findAPortNotInUse(3000, 3010).then(assertPort); + +// three arguments +findAPortNotInUse(3000, 3010, '127.0.0.1').then(assertPort); +findAPortNotInUse(3000, 3010, findPortCallback); + +// four argumentss +findAPortNotInUse(3000, 3010, '127.0.0.1', findPortCallback); + +// one argument +findAPortInUse([3000, 3005, 3006]).then(assertPort); +findAPortInUse(3000).then(assertPort); + +// two arguments +findAPortInUse([3000, 3005, 3006], findPortCallback); +findAPortInUse([3000, 3005, 3006], '127.0.0.1').then(assertPort); + +findAPortInUse(3000, findPortCallback); +findAPortInUse(3000, '127.0.0.1').then(assertPort); +findAPortInUse(3000, 3010).then(assertPort); + +// three arguments +findAPortInUse(3000, 3010, '127.0.0.1').then(assertPort); +findAPortInUse(3000, 3010, findPortCallback); + +// four argumentss +findAPortInUse(3000, 3010, '127.0.0.1', findPortCallback); diff --git a/types/node-portscanner/tsconfig.json b/types/portscanner/tsconfig.json similarity index 92% rename from types/node-portscanner/tsconfig.json rename to types/portscanner/tsconfig.json index f9ce1f0f99..d9844dae67 100644 --- a/types/node-portscanner/tsconfig.json +++ b/types/portscanner/tsconfig.json @@ -17,6 +17,6 @@ }, "files": [ "index.d.ts", - "node-portscanner-tests.ts" + "portscanner-tests.ts" ] } diff --git a/types/node-portscanner/tslint.json b/types/portscanner/tslint.json similarity index 100% rename from types/node-portscanner/tslint.json rename to types/portscanner/tslint.json