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

uniapp-easyuse-plugins

v1.1.0

Published

Uniapp easyuse plugin, include cache, logging, initialization, etc.

Readme

uniapp-easyuse-plugins

Usage

import { defineConfig, registerPlugins } from "uniapp-easyuse-plugins";
import appPagesConfig from "@/pages.json";

export function createApp() {
  const app = createSSRApp(App);

  const appConfig = defineConfig({
    router: { appPagesConfig }
  })
  const { callInit } = registerPlugins(app, appConfig);
  callInit();
}

AppConfig

// appConfig 允许接收一个函数,函数接收 vue app 实例作为参数
// 支持的配置和使用方法示列
const appConfig = defineConfig((app) => {
  return {
    // 缓存配置
    cache: {
      prefix: 'app', // 缓存键名前缀
      delimiter: '-', // 缓存前缀与键名之间的分隔符,默认为短横线 '-'
    },

    // 初始化配置
    // 代替 App.vue 中的 onLoad 等方法
    // 初始化参数获取
    init: async () => {
      const $cache = app.config.globalProperties.$cache
      const $store = app.config.globalProperties.$store

      // 获取当前租户
      $store.tenantId = $cache.get('tenantId') ?? '1'

      let accessToken: string | undefined = undefined

      // 获取缓存的 accessToken
      accessToken = $cache.get(config.accessTokenCacheName)

      // 从 url 中获取 accessToken
      const { query } = uni.getLaunchOptionsSync()
      if (query.access_token) {
        accessToken = query.access_token
      }

      const $request = app.config.globalProperties.$request
      if (!accessToken) {
        // 如果没有访问令牌,则取消所有等待发出的请求
        $request.cancel()
      }

      $store.accessToken = accessToken
    },

    // 状态管理配置
    // 一个简易的全局状态管理
    store: {
      onUpdate(value, oldValue) {
        const $cache = app.config.globalProperties.$cache
        const $$router = app.config.globalProperties.$$router

        const { loginPageRoute } = $$router

        // 当访问令牌更新,缓存当前访问令牌
        const originalAccessToken = oldValue.accessToken
        const accessToken = value.accessToken
        if (accessToken != originalAccessToken) {
          $cache.set(config.accessTokenCacheName, accessToken)

          // 当访问令牌无效时,跳转到登录页面
          if (!accessToken) {
            uni.reLaunch({
              url: `/${loginPageRoute}`,
            })
          }
        }
      },
    },

    // 全局请求配置
    request: {
      baseURL: import.meta.env.APP_BASE_URL,
      interceptors: {
        request(options) {
          const $store = app.config.globalProperties.$store
          const { accessToken, tenantId } = $store

          if (accessToken) {
            options.header['Authorization'] ??= `Bearer ${accessToken}`
          }

          if (tenantId) {
            options.header['Tenant-Id'] ??= tenantId
          }

          return options
        },
        response(response) {
          // 统一处理响应数据,将返回数据进行解包
          const responseData = response.data as AnyObject
          response.data = responseData.data

          // 当 response.errMsg 不等于 'request:ok' 时,会视为请求错误
          // 可以根据 response 的状态码,响应数据等信息,设置 response.errMsg 阻止响应完成
          // response.errMsg = '自定义错误信息'

          return response
        },
      },
    },

    // 路由配置
    router: {
      // uniapp 页面配置信息
      // 推荐通过 `import appPagesConfig from "@/pages.json"` 获取
      appPagesConfig: appPagesConfig,

      // 路由前置守卫,路由导航前执行
      beforeEach(to) {
        // 通过修改 to.fullPath 来改变导航页面
        // 例如通过检查 token 是否有效,判断是否应该跳转登录页
        const $$router = app.config.globalProperties.$$router
        const $store = app.config.globalProperties.$store
        const accessToken = $store.accessToken
        const { loginPageRoute } = $$router

        if (to.needLogin && !accessToken) {
          const redirect = encodeURIComponent(to.fullPath)
          to.fullPath = `/${loginPageRoute}?redirect=${redirect}`
        }
        if (to.isLoginPage && accessToken) {
          to.fullPath = `/pages/demo/home`
        }
        if (to.isHomePage) {
          to.fullPath = `/pages/demo/home`
        }
      },

      // 路由后置守卫,路由导航后执行
      afterEach(to, from) {
        //
      }
    },
  }
});