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

@yeepay/client-utils

v4.0.4

Published

shared utilities for yeepay client packages

Downloads

197

Readme

易宝支付 大前端 client utils

npm

3.0 版本之后,ESMOnly.

Features

  • getQueryObject: 获取 url 参数
  • setTokenFromUrl(key): 通过 url 中的参数 key 设置 TOKEN, 并存入 cookie 中
  • getToken: 从 cookie 中获取 TOKEN
  • removeToken: 从 cookie 中删除 TOKEN
  • serviceFactory: 请求封装的工厂函数

serviceFactory 介绍

基本使用

import { serviceFactory } from '@yeepay/client-utils'

const service = serviceFactory(
  {
    baseUrl: '/xxx-server',
    headers: {},
  },
  successCallback,
  failCallback,
  unauthorizedCallback,
  forbiddenCallback,
  notfoundCallback,
)

Mock数据

import { serviceFactory } from '@yeepay/client-utils'

const service = serviceFactory(
  {
    baseUrl: '/xxx-server',
    headers: {},
    mock: {
      modules: import.meta.glob('./mock/**/*.json', { eager: true }),
    },
  },
  successCallback,
  failCallback,
  unauthorizedCallback,
  forbiddenCallback,
  notfoundCallback,
)

比如 mock 数据文件 ./mock/get/user.json 内容如下:

{
  "code": "000000",
  "data": {
    "name": "John Doe"
  }
}

在你调用 uri 为 /get/user 的接口时,mock 数据将会被返回。

你还可以使用 js 文件来自定义 status、response、headers:

比如 mock 数据文件 ./mock/get/user.ts 内容如下:

import type { AxiosRequestConfig } from 'axios'

export default (config: AxiosRequestConfig) => {
  return [400, {
    code: '000000',
    data: {
      message: 'User not found'
    },
  }, { 'new-header-hello': 'world' }]
}

Debug 日志打印

开发者常常使用 console.log 日志打印来调试代码,且往往会忘记删除这些日志,导致线上环境也打印日志,影响性能与潜在安全风险。

@yeepay/client-utils 提供了 debug 模块来帮助开发者更好地控制日志打印。

基本使用

import { debug } from '@yeepay/client-utils'

debug.page1('page1 is loaded')

debug.api('fetch user api is called')

image

这些日志默认在开发环境打印,而在生产环境不打印。

如果想要在生产环境打印,可以在浏览器控制台执行:

debug.enableAll()
// 或者打印特定模块
debug.enable('page1')

// 恢复默认行为
debug.disable()