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

uni-toolkit

v0.3.2

Published

uni tools,uni app 工具库

Readme

uni-toolkit 🛠️

uniapp 工具库

这个仓库提供了一套用于 uniapp 开发的通用工具库,包含拦截器、hooks、工具函数和环境检测等功能,帮助解决平台兼容性问题和实现权限申请功能。

📋 目录

🎯 适用场景

  • 需要兼容低版本浏览器或手机系统
  • 需要处理不同平台(微信小程序、抖音小程序等)的特殊问题
  • 需要实现全局功能如路由守卫、数据存储优化等
  • 希望简化常见业务逻辑的处理
  • 需要处理 App、小程序权限申请问题
  • 需要使用封装好的 hooks 简化开发流程
  • 需要环境检测功能,针对不同环境进行特殊处理

🚀 安装

npm install uni-toolkit
# 或
pnpm add uni-toolkit
# 或
yarn add uni-toolkit

🚀 快速开始

基础使用

// 1. 导入拦截器
import { chooseImageInterceptor } from "uni-toolkit/interceptors";

// 2. 在应用入口处安装拦截器
app.use(chooseImageInterceptor);

// 3. 正常调用 uni API,拦截器会自动处理权限
uni.chooseImage({
  count: 1,
  sourceType: ["album", "camera"],
  success: (res) => {
    console.log("选择成功", res.tempFilePaths);
  }
});
// 使用 Hooks
import { useChooseImage } from "uni-toolkit/hooks";

const { chooseImage } = useChooseImage();

// 简化的图片选择
async function handleChooseImage() {
  try {
    const result = await chooseImage({ count: 1 });
    console.log("选择成功", result.tempFilePaths);
  } catch (error) {
    console.error("选择失败", error);
  }
}
import { isMpWeiXinWork } from "uni-toolkit/env";
// 使用工具函数
import { cloneDeep } from "uni-toolkit/tools";

// 深拷贝对象
const clonedData = cloneDeep(originalData);

// 环境检测
if (isMpWeiXinWork) {
  console.log("当前运行在微信小程序企业版环境");
}

📦 主要功能

🛡️ 拦截器 (Interceptors)

  • chooseImage 拦截器: 自动处理图片选择权限,支持 App 和小程序平台的相机、相册权限申请
  • chooseLocation 拦截器: 增强位置选择功能,自动处理权限和错误
  • makePhoneCall 拦截器: 增强拨打电话功能,提供参数校验和权限处理
  • route 拦截器: 路由增强,支持路由白名单和参数处理
  • setClipboardData 拦截器: 剪贴板增强,提供兼容性处理
  • setStorage 拦截器: 存储增强,支持数据加密和过期时间

🎣 Hooks

  • useChooseImage: 简化图片选择流程,自动处理权限申请
  • useDesignSize: 响应式设计尺寸处理
  • useOnShow: 页面显示生命周期处理

🛠️ 工具函数 (Tools)

  • 权限管理: 提供完整的权限检查、申请和提示功能
    • checkSelfPermission - 检查应用权限状态
    • checkPermissions - 检查小程序权限状态
    • requestPermissions - 请求小程序权限
    • checkAndRequestLocationAuth - 检查并请求位置权限
    • checkAndRequestImageAuth - 检查并请求图片选择权限
    • permissionAuth - 权限认证工具
    • showAuthTip - 显示权限提示对话框
    • showManualAuth - 引导用户手动授权
  • 通用工具:
    • cloneDeep - 高性能对象深拷贝功能
    • getCurrentPageRoute - 获取当前页面路由
    • isPageLevelComponent - 判断是否为页面级组件

🌍 环境检测 (Environment)

  • 平台检测: 检测当前运行环境和平台
    • isMpWeiXinWork - 检测是否为微信小程序企业版

📚 详细文档

📖 在线文档

访问我们的 在线文档网站 获取最新的文档和示例。

📝 文档部署

本项目使用 GitHub Actions 自动部署文档到 GitHub Pages。详细部署信息请参考 DEPLOY.md

入门指南

功能模块

示例项目

  • playground 示例 - 完整的示例项目,展示所有功能的实际应用
    • 图片选择示例:展示了 chooseImageInterceptor 的各种使用场景
    • 拦截器示例:展示了各种拦截器的实际效果
    • Hook 使用示例:展示了如何在实际项目中使用 Hooks

🤝 贡献

欢迎提交 Issue 和 Pull Request!详细信息请参考 贡献指南

📄 许可证

MIT