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 🙏

© 2026 – Pkg Stats / Ryan Hefner

dwy-ui

v1.0.0

Published

A lightweight React UI component library

Downloads

9

Readme

UA-Kit

React User Agent 组件库 — 智能设备检测与条件渲染

npm license

特性

  • 精准解析 — 浏览器、操作系统、设备类型、渲染引擎、CPU架构
  • 零依赖 — 纯函数解析引擎,仅依赖 React
  • SSR 友好 — 支持服务端渲染,可注入 UA 字符串和屏幕尺寸
  • 多格式输出 — ESM / CJS / UMD,完整 TypeScript 类型声明
  • 调试面板 — 内置 UADebugPanel 开发调试工具

安装

npm install ua-kit

快速开始

import { UAProvider, useUA, DeviceDetector, BrowserBadge } from 'ua-kit';

function App() {
  return (
    <UAProvider>
      <MyApp />
    </UAProvider>
  );
}

function MyApp() {
  const { browser, os, device, isWechat } = useUA();

  return (
    <div>
      <BrowserBadge showVersion />
      <DeviceDetector
        mobile={<MobileNav />}
        tablet={<TabletNav />}
        desktop={<DesktopNav />}
      />
    </div>
  );
}

核心 API

UAProvider

全局 UA 上下文提供者,在应用根节点包裹一次即可。

<UAProvider userAgent={req.headers['user-agent']}>
  <App />
</UAProvider>

支持 SSR 注入 userAgentscreenWidthscreenHeightdevicePixelRatio

useUA

获取当前 UA 解析结果。

const { browser, os, device, engine, cpu, isWechat, isApp, isTouch, isHover } = useUA();

parseUA

纯函数解析,不依赖 React。

import { parseUA } from 'ua-kit';

const info = parseUA('Mozilla/5.0...');
// { browser, os, device, engine, cpu, isWechat, isApp }

UADetectors

快速检测工具集。

import { UADetectors } from 'ua-kit';

UADetectors.isMobile();
UADetectors.isWechat();
UADetectors.isBrowser('Chrome', 90);

组件

DeviceDetector

根据设备类型条件渲染。

<DeviceDetector
  mobile={<MobileView />}
  tablet={<TabletView />}
  desktop={<DesktopView />}
  match={ua => ua.isWechat}  // 自定义匹配
/>

BrowserDetector / OSDetector

浏览器/操作系统条件渲染。

<BrowserDetector name="Chrome" minVersion={90}>
  <ModernFeature />
</BrowserDetector>

<OSDetector name={['iOS', 'Android']}>
  <MobilePay />
</OSDetector>

BrowserBadge / OSBadge / DeviceBadge

自动识别并展示彩色标识徽章。

<BrowserBadge showVersion size="large" />
<OSBadge showVersion />
<DeviceBadge />

ResponsiveGuard

结合 UA 和窗口尺寸的响应式守卫。

<ResponsiveGuard
  mobile={<MobileLayout />}
  tablet={<TabletLayout />}
  desktop={<DesktopLayout />}
  uaFirst={false}  // 是否优先使用UA而非窗口尺寸
/>

UADebugPanel

开发调试面板,展示完整 UA 解析信息。

{process.env.NODE_ENV === 'development' && <UADebugPanel />}

构建产物

| 格式 | 路径 | 用途 | |------|------|------| | ESM | dist/esm/index.js | 现代打包工具 | | CJS | dist/cjs/index.js | Node.js / 旧版工具 | | UMD | dist/umd/ua-kit.min.js | 浏览器直接引入 | | Types | dist/types/index.d.ts | TypeScript 类型 |

License

MIT