Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lukeed/is-offline
A tiny (174B) library to detect `offline` status & respond to changes in the browser.
https://github.com/lukeed/is-offline
Last synced: 2 days ago
JSON representation
A tiny (174B) library to detect `offline` status & respond to changes in the browser.
- Host: GitHub
- URL: https://github.com/lukeed/is-offline
- Owner: lukeed
- License: mit
- Created: 2017-12-08T02:40:24.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-28T01:53:01.000Z (almost 6 years ago)
- Last Synced: 2024-05-03T01:13:29.781Z (6 months ago)
- Language: JavaScript
- Homepage: https://jsfiddle.net/lukeed/8at2tg1e/
- Size: 10.7 KB
- Stars: 91
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# is-offline [![Build Status](https://travis-ci.org/lukeed/is-offline.svg?branch=master)](https://travis-ci.org/lukeed/is-offline)
> 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
```js
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`](#isofflinecheck).
## License
MIT © [Luke Edwards](https://lukeed.com)