# online-status-event

> Check if the browser have network connection

Latest version **1.0.2** (published 2020-09-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install online-status-event
pnpm add online-status-event
yarn add online-status-event
bun add online-status-event
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2020-09-09 |
| First published | 2019-04-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | John Nguyen |
| Maintainers | nguyenj |
| Keywords | browser, online, offline, network, detect, status, accessible, connected, connectivity |

## Links

- npm: https://www.npmjs.com/package/online-status-event
- Repository: https://github.com/nguyenj/online-status-event
- Homepage: https://github.com/nguyenj/online-status-event#readme
- Issues: https://github.com/nguyenj/online-status-event/issues
- npm.io page: https://npm.io/package/online-status-event

## Dependencies (1)

- [events](https://npm.io/package/events.md) ^3.0.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2020-09-09
- 1.0.1 — 2019-04-09

## README

# online-status-event

Wrapper around
[`window.navigator.onLine`](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine)
to let you know when your network is up or down.

## Install

```
$ npm online-status-event
```

## Usage

```
import { isOnline, start, stop } from 'online-status-event'

function handleOnlineStatus (status) {
    if (status) {
        // do something if online
    } else {
        // do something if offline
    }
}

// Manual check if the status is online or offline
handleOnlineStatus(isOnline())

// Listen to status changes and handle it accordingly
const statusEvent = start()
statusEvent.on('status', handleOnlineStatus)
```

## API

### Functions

Function | Arguments | Returns | Description
--- | --- | --- | ---
`isOnline` | none | boolean | Checks network status
`start` | none | object | Starts listening to status changes
`stop` | none | object | Stops listening to status changes

### Events

Name | Params | Description
--- | --- | ---
`status` | status(boolean) | Emits a status event with one boolean param value to indicate network status

## License

MIT Copyright (c) 2019 [John Nguyen](https://jnguyen.me)

---
_Source: https://npm.io/package/online-status-event · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
