You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

is-online

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-online - npm Package Compare versions

Comparing version
9.0.1
to
10.0.0
+6
-9
browser.js
/* eslint-env browser */
'use strict';
const publicIp = require('public-ip');
import publicIp from 'public-ip';
const isOnline = async options => {
export default async function isOnline(options) {
options = {
timeout: 5000,
ipVersion: 4,
...options
...options,
};
if (navigator && !navigator.onLine) {
if (!navigator?.onLine) {
return false;

@@ -21,7 +20,5 @@ }

return true;
} catch (_) {
} catch {
return false;
}
};
module.exports = isOnline;
}
+18
-22

@@ -1,19 +0,19 @@

declare namespace isOnline {
interface Options {
/**
Milliseconds to wait for a server to respond.
export type Options = {
/**
Milliseconds to wait for a server to respond.
@default 5000
*/
readonly timeout?: number;
@default 5000
*/
readonly timeout?: number;
/**
Internet Protocol version to use. This is an advanced option that is usually not necessary to be set, but it can prove useful to specifically assert IPv6 connectivity.
/**
[Internet Protocol version](https://en.wikipedia.org/wiki/Internet_Protocol#Version_history) to use.
@default 4
*/
readonly ipVersion?: 4 | 6;
}
}
This is an advanced option that is usually not necessary to be set, but it can prove useful to specifically assert IPv6 connectivity.
@default 4
*/
readonly ipVersion?: 4 | 6;
};
/**

@@ -31,12 +31,8 @@ Check if the internet connection is up.

```
import isOnline = require('is-online');
import isOnline from 'is-online';
(async () => {
console.log(await isOnline());
//=> true
})();
console.log(await isOnline());
//=> true
```
*/
declare function isOnline(options?: isOnline.Options): Promise<boolean>;
export = isOnline;
export default function isOnline(options?: Options): Promise<boolean>;
+29
-21

@@ -1,18 +0,16 @@

'use strict';
const os = require('os');
const got = require('got');
const publicIp = require('public-ip');
const pAny = require('p-any');
const pTimeout = require('p-timeout');
import os from 'node:os';
import got, {CancelError} from 'got';
import publicIp from 'public-ip';
import pAny from 'p-any';
import pTimeout from 'p-timeout';
// Use Array#flat when targeting Node.js 12
const flat = array => [].concat(...array);
const appleCheck = options => {
const gotPromise = got('https://captive.apple.com/hotspot-detect.html', {
timeout: options.timeout,
dnsLookupIpVersion: options.ipVersion === 6 ? 'ipv6' : 'ipv4',
timeout: {
request: options.timeout,
},
dnsLookupIpVersion: options.ipVersion,
headers: {
'user-agent': 'CaptiveNetworkSupport/1.0 wispr'
}
'user-agent': 'CaptiveNetworkSupport/1.0 wispr',
},
});

@@ -27,3 +25,3 @@

} catch (error) {
if (!(error instanceof got.CancelError)) {
if (!(error instanceof CancelError)) {
throw error;

@@ -39,11 +37,12 @@ }

const isOnline = options => {
// Note: It cannot be `async`` as then it looses the `.cancel()` method.
export default function isOnline(options) {
options = {
timeout: 5000,
ipVersion: 4,
...options
...options,
};
if (flat(Object.values(os.networkInterfaces())).every(({internal}) => internal)) {
return Promise.resolve(false);
if (Object.values(os.networkInterfaces()).flat().every(({internal}) => internal)) {
return false;
}

@@ -77,3 +76,3 @@

return true;
})()
})(),
]);

@@ -88,4 +87,13 @@

});
};
module.exports = isOnline;
// TODO: Use this instead when supporting AbortController.
// try {
// return await pTimeout(promise, options.timeout);
// } catch {
// for (const query of queries) {
// query.cancel();
// }
// return false;
// }
}
{
"name": "is-online",
"version": "9.0.1",
"version": "10.0.0",
"description": "Check if the internet connection is up",

@@ -16,7 +16,13 @@ "license": "MIT",

],
"type": "module",
"exports": {
"types": "./index.d.ts",
"node": "./index.js",
"default": "./browser.js"
},
"engines": {
"node": ">=10"
"node": ">=14.16"
},
"scripts": {
"test": "xo && ava test.js && tsd"
"test": "xo && ava && tsd"
},

@@ -51,18 +57,17 @@ "files": [

"dependencies": {
"got": "^11.8.0",
"p-any": "^3.0.0",
"p-timeout": "^3.2.0",
"public-ip": "^4.0.4"
"got": "^12.1.0",
"p-any": "^4.0.0",
"p-timeout": "^5.1.0",
"public-ip": "^5.0.0"
},
"devDependencies": {
"ava": "^2.4.0",
"tsd": "^0.13.1",
"xo": "^0.34.1"
"ava": "^4.3.0",
"tsd": "^0.20.0",
"xo": "^0.49.0"
},
"browser": "browser.js",
"xo": {
"rules": {
"unicorn/prefer-optional-catch-binding": "off"
}
"ava": {
"files": [
"test.js"
]
}
}

@@ -7,9 +7,9 @@ # is-online

In the browser you have [`navigator.onLine`](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine.onLine), but it's useless as it only tells you if there's a local connection, and not whether the internet is accessible.
In the browser, there is already [`navigator.onLine`](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine.onLine), but it's useless as it only tells you if there's a local connection, and not whether the internet is accessible.
## Install
```sh
npm install is-online
```
$ npm install is-online
```

@@ -19,8 +19,6 @@ ## Usage

```js
const isOnline = require('is-online');
import isOnline from 'is-online';
(async () => {
console.log(await isOnline());
//=> true
})();
console.log(await isOnline());
//=> true
```

@@ -49,4 +47,6 @@

Internet Protocol version to use. This is an advanced option that is usually not necessary to be set, but it can prove useful to specifically assert IPv6 connectivity.
The [Internet Protocol version](https://en.wikipedia.org/wiki/Internet_Protocol#Version_history) to use.
This is an advanced option that is usually not necessary to be set, but it can prove useful to specifically assert IPv6 connectivity.
## How it works

@@ -53,0 +53,0 @@