Skip to content

Commit

Permalink
Meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 20, 2019
1 parent db6fd61 commit b05267f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 35 deletions.
5 changes: 2 additions & 3 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"contributors": [
"silverwind <me@silverwind.io> (github.com/silverwind)"
],
"engines": {
"node": ">=8"
},
Expand Down
22 changes: 12 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,41 @@ 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<boolean>` 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

Type: `object`

##### timeout

Type: `number`
Type: `number`<br>
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
36 changes: 18 additions & 18 deletions test-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
})();

0 comments on commit b05267f

Please sign in to comment.