From b05267f52af3c9ade754b0b83cc48b6dfd34db82 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 20 Apr 2019 14:25:01 +0700 Subject: [PATCH] Meta tweaks --- browser.js | 5 ++--- index.js | 2 +- package.json | 3 --- readme.md | 22 ++++++++++++---------- test-browser.js | 36 ++++++++++++++++++------------------ 5 files changed, 33 insertions(+), 35 deletions(-) diff --git a/browser.js b/browser.js index 02961a0..bca0008 100644 --- a/browser.js +++ b/browser.js @@ -5,11 +5,10 @@ const pAny = require('p-any'); const prependHttp = require('prepend-http'); const URL = require('url-parse'); -module.exports = hosts => { +module.exports = async hosts => { return pAny(arrify(hosts).map(url => { return new Promise(resolve => { - let {hostname, protocol, port} = new URL(prependHttp(url)); - protocol = protocol || ''; + let {hostname, protocol = '', port} = new URL(prependHttp(url)); port = port ? `:${port}` : ''; const image = new Image(); diff --git a/index.js b/index.js index 9063a3f..89c8844 100644 --- a/index.js +++ b/index.js @@ -55,7 +55,7 @@ const isTargetReachable = async target => { return isPortReachable(url.port, {host: address}); }; -module.exports = (destinations, options) => { +module.exports = async (destinations, options) => { options = {...options}; options.timeout = typeof options.timeout === 'number' ? options.timeout : 5000; diff --git a/package.json b/package.json index 01d39a4..8ae22d6 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,6 @@ "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, - "contributors": [ - "silverwind (github.com/silverwind)" - ], "engines": { "node": ">=8" }, diff --git a/readme.md b/readme.md index 36d8e4a..57c8712 100644 --- a/readme.md +++ b/readme.md @@ -35,15 +35,15 @@ const isReachable = require('is-reachable'); ### isReachable(targets, [options]) -Returns a `Promise` for a `boolean` which is `true` if any of the `targets` are reachable. +Returns a `Promise` which is `true` if any of the `targets` are reachable. #### targets -Type: `string` `string[]` +Type: `string | string[]` 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][] are supported (e.g. `ftp://`, `mysql://`, `redis://` and more). +[Well-known protocols][] are supported (for example: `ftp://`, `mysql://`, `redis://` and more). #### options @@ -51,23 +51,25 @@ Type: `object` ##### timeout -Type: `number` +Type: `number`
+Default: `5000` -Timeout in milliseconds after which a request is considered failed. Default: `5000`. +Timeout in milliseconds after which a request is considered failed. -## Contributors +## Related -- [silverwind](https://github.com/silverwind) +- [is-online](https://github.com/sindresorhus/is-online) - Check if the internet connection is up -## Related +## Maintainers -- [is-online](https://github.com/sindresorhus/is-online) - Check if the internet connection is up +- [Sindre Sorhus](https://github.com/sindresorhus) +- [silverwind](https://github.com/silverwind) ## License -MIT © [Sindre Sorhus](https://sindresorhus.com) +MIT [Well-known protocols]: https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml diff --git a/test-browser.js b/test-browser.js index e0dbdf7..b29cb1a 100644 --- a/test-browser.js +++ b/test-browser.js @@ -3,26 +3,26 @@ 'use strict'; const isReachable = require('./browser'); -isReachable('google.com').then(reachable => { - console.log('reachable', reachable); -}); +(async () => { + console.log('reachable', await isReachable('google.com')); +})(); -isReachable('google.com:80').then(reachable => { - console.log('reachable', reachable); -}); +(async () => { + console.log('reachable', await isReachable('google.com:80')); +})(); -isReachable('//google.com').then(reachable => { - console.log('reachable', reachable); -}); +(async () => { + console.log('reachable', await isReachable('//google.com')); +})(); -isReachable('https://google.com').then(reachable => { - console.log('reachable', reachable); -}); +(async () => { + console.log('reachable', await isReachable('https://google.com')); +})(); -isReachable('343645335341233123125235623452344123.com').then(reachable => { - console.log('not reachable', reachable); -}); +(async () => { + console.log('not reachable', await isReachable('343645335341233123125235623452344123.com')); +})(); -isReachable('https://google.com/notfound.js').then(reachable => { - console.log('not reachable', reachable); -}); +(async () => { + console.log('not reachable', await isReachable('https://google.com/notfound.js')); +})();