Noncommital Premarital Mischief
Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

is-offline

2.1.1 • Public • Published

is-offline Build Status

A tiny (174B) library to detect offline status & respond to changes in the browser.

This module exposes three module definitions:

  • ES Module: dist/is-offline.es.js
  • CommonJS: dist/is-offline.js
  • UMD: dist/is-offline.min.js

If using the UMD bundle, the library is exposed as is-offline globally.

Install

$ npm install --save is-offline

Usage

import { check, watch } from 'is-offline';
 
let foobar = bool => console.log('Am I offline?', bool);
 
// Check if currently offline
check().then(foobar);
 
// Setup a "watcher" to respond to all online/offline changes
let unwatch = watch(foobar);
 
// The "watcher" will be active until it's deactivated
unwatch();

API

isOffline.check()

Returns: Promise

Resolves a Boolean to indicate offline status. For clarity, true means that you are offline.

isOffline.watch(fn)

Returns: Function

Returns a function that is used to disable/unmount the event listeners.

fn

Type: Function

The function to run whenever the network status changes. It receives a Boolean value, just like isOffline.

License

MIT © Luke Edwards

install

npm i is-offline

Downloadsweekly downloads

404

version

2.1.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability