# sp-isoffline

> is online and offline on nodejs; 检测网络状态（nodejs）

Latest version **0.0.5** (published 2021-11-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install sp-isoffline
pnpm add sp-isoffline
yarn add sp-isoffline
bun add sp-isoffline
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2021-11-04 |
| First published | 2021-10-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | sparrow |
| Maintainers | sparrowend |
| Keywords | nodejs, online, offline, 检测网络, 断线重连, 是否连网 |

## Links

- npm: https://www.npmjs.com/package/sp-isoffline
- Repository: https://github.com/lianglei-git/sp-isoffline
- Homepage: https://github.com/lianglei-git/sp-isoffline#readme
- Issues: https://github.com/lianglei-git/sp-isoffline/issues
- npm.io page: https://npm.io/package/sp-isoffline

## Recent versions

- 0.0.5 (latest) — 2021-11-04
- 0.0.4 — 2021-10-14
- 0.0.3 — 2021-10-14
- 0.0.2 — 2021-10-13
- 0.0.1 — 2021-10-13

## README

# sp-isoffline
1. is online on nodejs by ping hosts: www.baidu.com, weixin.qq.com...
2. offline to online on nodejs 

## Install
`npm install sp-isoffline`
or
`yarn add sp-isoffline`

## api
### isonline: 
`网络是否处于在线状态(一次性（ one-off ）) code: `
```js
import {isonline} from 'sp-isoffline'

/*
 * dnses: [...]
 */
isonline().then(status => {
    if(status) {
        // online
    }else {
        // offline
    }
})
```

### offlineListener：
`网络监听器， 默认三秒 轮询 code：`

```js 
offlineListener({
    time: 1000, // 间隔
    // interval: 9, // 次数
    offline(callback) { // 网络断开
        console.log('网络断开')
        callback(({ status }) => {
            if (status) console.log('联网成功')
            else console.log('网络连接失败')
        })
    },
    online({ status }) { // 网络正常情况下
        if (status) console.log('网络正常')
    }
})
```

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