npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nw-detect

v2.23.1

Published

> 平台检测组件

Downloads

219

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()

检测是否是音乐应用

isIos()

检测是否是iOS设备

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

检测是否是iOS设备

isiPad()

检测是否是iPad设备

isApp()

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

isQQ()

检测是否是QQ应用

isAndroid

检测是否安卓应用

isSupportWebp

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

isSupportWebpAsync

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