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

epackage-device-detect

v2.0.1

Published

通过ua-parser-js检测用户当前使用的设备、系统、网络、电池等硬性环境。

Downloads

50

Readme

环境检测工具 V2

Npm package version Npm package monthly downloads made-for-VSCode saythanks

检测用户当前使用的设备、系统等硬件环境。

V2.0.1发行

!!!V2.0.0版本因代码兼容问题,导致出现异常问题,请及时更新V2.0.1版本。

V2.0.1版本现已发行,该版本基于ua-parser-js进行重构,兼容性得到显著提高,并支持使用更多配置选项。

  • ✅ 新增:使用getEngineView检测渲染器名称及版本。
  • ✅ 新增:品牌检测方法BrandFunc,支持热门品牌类型检测。
  • 🚀 重构:getBrowserView、getDeviceView自定义方法变更,现已支持更多类型浏览器检测。
  • 🚀 重构:检测方法采用全新逻辑处理,结合uaparser.js实现。
  • 🔙 移除:getBrowserView的isBrowser属性已移除。
  • 🔙 移除:isBrowser()方法已移除。
  • 🩹 修复:V2.0.0版本因未对关键方法做兼容处理导致异常报错。

建议您使用最新V2.0.1版本。

说明

部分方法、函数可能使用废弃的JS API实现,或使用了实验性功能,该标准取决于MDN文档,如使用包含下列特殊备注的方法、函数,epackage-device-detect默认您已接受未知的风险。

特殊标识列表:

🧪:实验性,该方法采用了实验性API实现,未来版本可能会被删除。

🚮:废弃的,该方法使用了已废弃的JS API实现,epackage-device-detect将会在未来版本中找到最优解决方案。

❌:不可使用,该标识下的方法暂未实现,但在未来版本中可能会实现,未实现方法返回值默认为true。

安装

  • npm

npm install epackage-device-detect

  • yarn:

yarn add epackage-device-detect

如何使用

您可以使用以下方法导入:

import device from 'epackage-device-detect';

function getDevice() {
  const browserData = device.getBrowserView();
  const systemData = device.getSystemView();

  console.log(browserData, systemData);
}

如果您不需要全部引入,您可以选择使用部分API:

import { getBrowserView, getSystemView } from 'epackage-device-detect';

// ...同上

函数

| 函数名 | 说明 | 备注 | | ----------------- | ---------------- | ---- | | getBrowserView | 获取浏览器信息 | - | | getSystemView | 获取系统信息 | - | | getBatteryView | 获取电池状态信息 | 🚮 | | getConnectionView | 获取网络信息 | 🧪 | | getDeviceView | 获取设备信息 | - | | getEngineView | 获取渲染器信息 | - |

方法

浏览器检测

| 方法名 | 说明 | 返回值 | 备注 | | ---------------- | ---------------------------------------- | ------- | ---- | | isEdge | 返回 true 时为 EdgeEdge Chromium | boolean | - | | isOpera | 返回 true 时为 Opera | boolean | - | | isSafari | 返回 true 时为 Safari | boolean | - | | isChrome | 返回 true 时为 Chrome | boolean | - | | isFirefox | 返回 true 时为 Firefox | boolean | - | | isIES | 返回 true 时为 Internet Explorer | boolean | - | | isQQ | 返回 true 时为 QQ浏览器 | boolean | - | | isSogou | 返回 true 时为 搜狗浏览器 | boolean | 🧪 | | is2345 | 返回 true 时为 2345浏览器 | boolean | - | | is360 | 返回 true 时为 360浏览器 | boolean | - | | isYandex | 返回 true 时为 Yandex浏览器 | boolean | - | | isChromium | 返回 true 时为 Chromium浏览器 | boolean | - | | isSamsungBrowser | 返回 true 时为 Samsung浏览器 | boolean | - |

设备检测

| 方法名 | 说明 | 返回值 | 备注 | | ------------------ | ----------------------------------------------------------------- | ------- | ---- | | isMobile | 返回 true 时为 移动端 | boolean | - | | isMobileOnly | 返回 true 时为 手机端,区别于isMobile,此方法将严格校验手机设备 | boolean | - | | isAndroidPhone | 返回 true 时为 安卓系统手机端 | boolean | - | | isAndroidTablet | 返回 true 时为 安卓系统平板设备 | boolean | - | | isWindowPhone | 返回 true 时为 Windows系统手机端 | boolean | - | | isWindowTablet | 返回 true 时为 Windows系统平板设备 | boolean | - | | isIphone | 返回 true 时为 iphone | boolean | - | | isIpod | 返回 true 时为 ipod | boolean | - | | isIpad | 返回 true 时为 ipad | boolean | - | | isMacOS | 返回 true 时为 mac端 | boolean | - | | isTablet | 返回 true 时为 平板设备 | boolean | - | | isTV | 返回 true 时为 电视端 | boolean | - | | isWearable | 返回 true 时为 穿戴设备 | boolean | - | | isConsole | 返回 true 时为 接口管理设备 | boolean | - | | isEmbedded | 返回 true 时为 嵌入式设备 | boolean | - | | isBlackberryPhone | 返回 true 时为 黑莓手机端 | boolean | - | | isBlackberryTablet | 返回 true 时为 黑莓平板电脑设备 | boolean | - | | isDesktop | 返回 true 时为 台式机 | boolean | - | | isFxos | 返回 true 时为 可扩展操作系统 | boolean | 🧪 | | isFxosPhone | 返回 true 时为 可扩展操作系统 手机端 | boolean | 🧪 | | isFxosTablet | 返回 true 时为 可扩展操作系统 平板电脑设备 | boolean | 🧪 | | isBrowser | 返回 true 时为 浏览器,该方法已弃用 | boolean | ❌ |

系统检测

| 方法名 | 说明 | 返回值 | 备注 | | -------------- | ---------------------------------- | ------- | ---- | | isAndroid | 返回 true 时为 Android 系统 | boolean | - | | isWindow | 返回 true 时为 Windows 系统 | boolean | - | | isIos | 返回 true 时为 IOS 系统 | boolean | - | | isMeego | 返回 true 时为 Meego 系统 | boolean | - | | isBlackBerryOS | 返回 true 时为 BlackBerryOS 系统 | boolean | - | | isCentOS | 返回 true 时为 CentOS 系统 | boolean | - | | isFirefoxOS | 返回 true 时为 FirefoxOS 系统 | boolean | - | | isHarmonyOS | 返回 true 时为 HarmonyOS 系统 | boolean | - | | isLinux | 返回 true 时为 Linux 系统 | boolean | - | | isMacOS | 返回 true 时为 MacOS 系统 | boolean | - | | isMinix | 返回 true 时为 Minix 系统 | boolean | - | | isNintendoOS | 返回 true 时为 NintendoOS 系统 | boolean | - | | isPlayStation | 返回 true 时为 PlayStation 系统 | boolean | - | | isUbuntu | 返回 true 时为 Ubuntu 系统 | boolean | - | | isUnix | 返回 true 时为 Unix 系统 | boolean | - | | isWebOS | 返回 true 时为 WebOS 系统 | boolean | - |

品牌检测

| 方法名 | 说明 | 返回值 | 备注 | | ------------ | ------------------------- | ------- | ---- | | isHTC | 返回 true 时为 HTC | boolean | - | | isLenovo | 返回 true 时为 联想 | boolean | - | | isLG | 返回 true 时为 LG | boolean | - | | isMeizu | 返回 true 时为 魅族 | boolean | - | | isMicrosoft | 返回 true 时为 微软 | boolean | - | | isMotorola | 返回 true 时为 摩托罗拉 | boolean | - | | isNintendo | 返回 true 时为 任天堂 | boolean | - | | isNokia | 返回 true 时为 诺基亚 | boolean | - | | isNvidia | 返回 true 时为 英伟达 | boolean | - | | isOPPO | 返回 true 时为 Oppo | boolean | - | | isRealme | 返回 true 时为 真我 | boolean | - | | isSamsung | 返回 true 时为 三星 | boolean | - | | isTesla | 返回 true 时为 特斯拉 | boolean | - | | isVivo | 返回 true 时为 Vivo | boolean | - | | isXiaomi | 返回 true 时为 小米 | boolean | - | | isZTE | 返回 true 时为 中兴 | boolean | - | | isOnePlus | 返回 true 时为 一加 | boolean | - | | isSharp | 返回 true 时为 夏普 | boolean | - | | isBlackberry | 返回 true 时为 黑莓 | boolean | - | | isApple | 返回 true 时为 苹果 | boolean | - | | isAmazon | 返回 true 时为 亚马逊 | boolean | - | | isDell | 返回 true 时为 戴尔 | boolean | - | | isHuawei | 返回 true 时为 华为 | boolean | - | | isHP | 返回 true 时为 惠普 | boolean | - |

以下列表中展示的为 epackage-device-detect 自定义属性,其余原生属性不在此处展示,您可在MDN Navigator文档中查看。

getBrowserView返回值

| 属性名 | 说明 | 返回值 | 备注 | | --------- | --------------------------------------------------------------------------- | ----------------------------------------------------------------- | ---- | | isBrowser | 是否为浏览器,返回 true 时表示当前访问环境为浏览器,该属性已弃用 | boolean | ❌ | | browser | 返回 name 当前浏览器名称、 version 当前浏览器版本号、major 当前浏览器主版本 | object<name: string, version: string, major: string> | 'unknown' | - |

browser属性:

name:浏览器名称,例如:

2345Explorer, 360 Browser, Amaya, Android Browser, Arora, Avant, Avast, AVG, BIDUBrowser, Baidu, Basilisk, Blazer, Bolt, Brave, Bowser, Camino, Chimera, [Mobile] Chrome [Headless/WebView], Chromium, Cobalt, Comodo Dragon, Dillo ...

version:浏览器版本号,例如:

5.1.21214

major:浏览器主版本号,例如:

5

查看详细文档,点击查看getBrowser()

getSystemView返回值

| 属性名 | 说明 | 返回值 | 备注 | | ------ | -------- | ------------------------------------- | ---- | | system | 系统名称 | object<name: string, version: string> | - |

system属性:

name:系统名称,例如:

AIX, Amiga OS, Android[-x86], Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS,Contiki, Fedora, Firefox OS, FreeBSD, Debian, Deepin, DragonFly, elementary OS, Fuchsia, Gentoo, GhostBSD, GNU, Haiku, HarmonyOS, HP-UX, Hurd, iOS, Joli, KaiOS, Linpus, Linspire, Linux ...

version:系统版本:例如:

12

查看详细文档,点击查看getEngine()

getConnectionView返回值

| 属性名 | 说明 | 返回值 | 备注 | | -------- | -------- | -------------------------------------------------- | ---- | | downlink | 网络速度 | object<speed: string, value: string, unit: string> | - |

downlink属性:

speed:当前网络速度,例如:

6.4M/s

value:当前网络速度值,例如:

6.4

unit:当前网络速度单位,例如:

M/s

getDeviceView返回值

| 属性名 | 说明 | 返回值 | 备注 | | ------ | -------- | -------------------------------------------------- | ---- | | device | 设备类型 | object<model: string, type: string, vendor:string> | - |

device属性:

model:设备型号,例如:

SM-X706B

type:设备类型,例如:

mobile, tablet, smarttv, console, wearable, embedded

vendor:设备商家,例如:

Acer, Alcatel, Amazon, Apple, Archos, ASUS, AT&T, BenQ, BlackBerry, Dell, Essential, Facebook, Fairphone, GeeksPhone, Google, HP, HTC, Huawei, Jolla, Kobo, Lenovo, LG, Meizu,Microsoft, Motorola, Nexian, Nintendo, Nokia, Nvidia, OnePlus,  OPPO, Ouya, Palm ...

查看详细文档,点击查看getDevice()

getEngineView返回值

| 属性名 | 说明 | 返回值 | 备注 | | ------ | ---------- | ------------------------------------- | ---- | | engine | 渲染器类型 | object<name: string, version: string> | - |

engine属性:

name:渲染器名称,例如:

Amaya, Blink, EdgeHTML, Flow, Gecko, Goanna, iCab, KHTML, LibWeb, Links, Lynx, NetFront, NetSurf, Presto, Tasman, Trident, w3m, WebKit

version:渲染器版本:例如:

2.5.25

查看详细文档,点击查看getEngine()

许可证

MIT