Socket
Book a DemoInstallSign in
Socket

@yeepay/client-utils

Package Overview
Dependencies
Maintainers
8
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yeepay/client-utils

shared utilities for yeepay client packages

3.1.0
latest
npmnpm
Version published
Weekly downloads
287
1494.44%
Maintainers
8
Weekly downloads
 
Created
Source

易宝支付 大前端 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: {},
    // glob mock 数据文件位置
    mockModules: 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' }]
}

Keywords

utils

FAQs

Package last updated on 30 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.