# nw-detect

> > 平台检测组件

Latest version **2.31.1** (published 2026-06-08) · 0 weekly downloads

## Install

```sh
npm install nw-detect
pnpm add nw-detect
yarn add nw-detect
bun add nw-detect
```

## Health

**Score 50/100 (C)** — status: active.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.31.1 |
| Published | 2026-06-08 |
| First published | 2017-10-24 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 58.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | guoyeeg, azgaga, liushichuan, yaochen, shenyuan, aflyermin, ignous, jeekdong, yousy, luofeiyue, whiskeyi, fechen, yun77op |

## Links

- npm: https://www.npmjs.com/package/nw-detect
- npm.io page: https://npm.io/package/nw-detect

## Dependencies (1)

- [nejsbridge](https://npm.io/package/nejsbridge.md) *

## Recent versions

- 2.31.1 (latest) — 2026-06-08
- 2.31.0 — 2025-06-23
- 2.30.0 — 2025-06-22
- 2.29.0 — 2025-06-22
- 2.28.2 — 2025-04-17
- 2.28.1 — 2025-04-17
- 2.28.0 — 2025-04-10
- 2.27.1 — 2025-04-09
- 2.27.0 — 2025-04-08
- 2.26.0 — 2024-12-11
- 2.25.0 — 2024-12-11
- 2.24.1 — 2024-11-12
- 2.24.0 — 2024-11-11
- 2.23.1 — 2024-04-02
- 2.23.0 — 2024-01-29
- … 47 more at https://npm.io/package/nw-detect/versions

## README

# nw-detect

> 平台检测组件

## 安装

```sh
$ yarn add nw-detect
```

## API

```js
import {isWeixin, ios} from 'nw-detect';
```

### `isInLofter(options = { isDev: false })`
```javascript
/**
* 异步返回，通过JSBridge等方式，严格的检查当前H5运行环境是否为Lofter App内
* Promise的返回值为number类型，只可能为 0 | 1 | 2这三个值之一
* 如果当前不在客户端内，resolve 0
* 如果当前在客户端内，并且版本高于6.8.2，resolve 1
* 如果当前在客户端版本内，但是版本低于6.8.2，resolve 2
* @param options
* @param options.isDev 是否为开发环境，默认为false，传入true则表示当前为开发环境，Promise会resolve 1
* @returns Promise<0|1|2>
* */
export function isInLofter(options = {
  isDev: false
}) {
  ...
}
```

### getLofterVersion()
获取string格式的LOFTER版本号，如'1.1.1'

### getSnailVersion()
获取string格式的蜗牛版本号，如'1.1.1'

### formateVersion(version)
```javascript
/**
* 格式化版本号，变成可比较大小的数字
* @param {string} version 想要格式化的版本号，格式必须符合 x.x.x
* @returns {number}
*/
```

### compareVersion(version1, version2)
```javascript
/**
* 比较2个字符串版本号，返回版本号1-版本号2的结果
* @param {string} version1 版本号1
* @param {string} version2 版本号2
* @returns {number} version1-version2的结果
*/
```

### isUpAppVersion(vesion)
```javascript
/**
* 判断当前客户端内版本号是否大于等于给定的版本号
* 支持Lofter和蜗牛客户端
* @param {string} version 想要比较的版本号，x.x.x格式
* @returns {boolean} 当前版本是否大于等于给定版本
*/
```

### `isWeixin()`

检测是否是微信

### `isXiaomi()`

检测是否是小米手机

### `isYueduApp()`

检测是否是阅读应用

### `isLofter()`

检测是否是LOFTER应用

### `isLofterVC()`

检测是否是LOFTER破次元恋人 独立APP 应用

### `isComicApp()`

检测是否是漫画应用

### `isSnail()`

检测是否是蜗牛应用

### `isMusic()`

检测是否是音乐应用

### `isIos()`

检测是否是iOS设备

### `ios()` (命名不规范，不推荐使用，保留仅用于防止已引用工程出错)

检测是否是iOS设备

### `isiPad()`

检测是否是iPad设备

### `isApp()`

检测是否是阅读、漫画、蜗牛、音乐或者lofter应用

### `isQQ()`

检测是否是QQ应用

### `isAndroid`

检测是否安卓应用

### `isSupportWebp`
`推荐使用`-检测浏览器是否支持webp格式的图片
**调用此方法，会优先读取由精准webp能力检测的`isSupportWebpAsync`方法写入的localstorage检测结果，如果没有本地存储结果的，才会在后台再去调用`isSupportWebpAsync`的方法并且异步地更新localstorage**

### `isSupportWebpAsync`
```javascript
import { isSupportWebpAsync } from 'nw-detect';
/**
* 异步检查浏览器是否支持webp格式的图片，准确性比`isSupportWebp`高很多
* `isSupportWebp`在支持Webp图片的Safari浏览器中依然返回false
* 检查过一次以后会在localstorage进行本地记录，下次调用会更快返回
* @returns Promise<boolean>
* */
isSupportWebpAsync().then(res => {
  console.log('当前浏览器环境是否支持Webp图片',res)
})
```

### `getIosVersion` 
获取iOS设备系统版本号，非iOS设备返回null

### `getAndroidVersion` 
获取Android设备系统版本号，非Android设备返回null

### `isUpIosVersion`
判断当前iOS版本是否大于等于给定的版本号，如果不是iOS系统，返回false

### `isUpAndroidVersion`
判断当前Android版本是否大于等于给定的版本号，如果不是Android系统，返回false

### `getChromeVersion`
从UA中获取Chrome版本号, 返回版本号整数，Number类型，如72
如果UA中没有Chrome版本号，返回null

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