nw-detect

平台检测组件

Usage no npm install needed!

<script type="module">
  import nwDetect from 'https://cdn.skypack.dev/nw-detect';
</script>

README

nw-detect

平台检测组件

安装

$ yarn add nw-detect

API

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

isInLofter(options = { isDev: false })

/**
* 异步返回,通过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)

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

compareVersion(version1, version2)

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

isUpAppVersion(vesion)

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

isWeixin()

检测是否是微信

isXiaomi()

检测是否是小米手机

isYueduApp()

检测是否是阅读应用

isLofter()

检测是否是Lofter应用

isComicApp()

检测是否是漫画应用

isSnail()

检测是否是蜗牛应用

isMusic()

检测是否是音乐应用

ios()

检测是否是iOS设备

isiPad()

检测是否是iPad设备

isApp()

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

isQQ()

检测是否是QQ应用

isAndroid

检测是否安卓应用

isSupportWebp

检测浏览器是否支持webp格式的图片

isSupportWebpAsync

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