diff --git a/types/is-reachable/index.d.ts b/types/is-reachable/index.d.ts new file mode 100644 index 0000000000..6e2ea2d62f --- /dev/null +++ b/types/is-reachable/index.d.ts @@ -0,0 +1,39 @@ +// Type definitions for is-reachable 3.0 +// Project: https://github.com/sindresorhus/is-reachable#readme +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = isReachable; + +/** + * Check if servers are reachable. + * + * The Node.js version will do a TCP handshake with the target's port. It attempts to detect cases where a router + * redirects the request to itself. + * + * The browser version is limited by the fact that browsers cannot connect to arbitrary ports. It only supports + * HTTP and HTTPS and the check relies on the `/favicon.ico` path being present. + * + * @param targets One or more targets to check. Can either be a full [URL](https://nodejs.org/api/url.html) + * like `https://hostname`, `hostname:port` or just `hostname`. When the protocol is missing from a target + * `http` is assumed. + * + * [Well-known protocols](http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml) + * are supported (e.g. `ftp://`, `mysql://`, `redis://` and more). + * + * @returns A `Promise` for a `boolean` which is `true` if any of the `targets` are reachable. + */ +declare function isReachable( + targets: string | string[], + options?: isReachable.Options +): Promise; + +declare namespace isReachable { + interface Options { + /** + * Timeout in milliseconds after which a request is considered failed. + * @default 5000 + */ + timeout?: number; + } +} diff --git a/types/is-reachable/is-reachable-tests.ts b/types/is-reachable/is-reachable-tests.ts new file mode 100644 index 0000000000..d497d004f2 --- /dev/null +++ b/types/is-reachable/is-reachable-tests.ts @@ -0,0 +1,4 @@ +import isReachable = require('is-reachable'); + +isReachable('sindresorhus.com'); // $ExpectType Promise +isReachable('google.com:80', { timeout: 10 }); // $ExpectType Promise diff --git a/types/is-reachable/tsconfig.json b/types/is-reachable/tsconfig.json new file mode 100644 index 0000000000..c30236ebd5 --- /dev/null +++ b/types/is-reachable/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "is-reachable-tests.ts" + ] +} diff --git a/types/is-reachable/tslint.json b/types/is-reachable/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/is-reachable/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }