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

@krysent/kite-core

v1.0.1

Published

框架内核 - 状态管理、请求封装、权限逻辑、工具函数

Readme

@krysent/kite-core

框架内核包,提供核心功能:状态管理、请求封装、权限逻辑。

请求封装 (@krysent/kite-core/request)

功能特性

  • 请求去重:自动处理重复请求,避免重复调用
  • Loading 计数:智能管理全局 Loading 状态
  • 统一错误处理:标准化的错误处理机制

安装

pnpm add @krysent/kite-core

基础使用

import { request } from '@krysent/kite-core'

// GET 请求
const users = await request.get('/api/users')

// POST 请求
const result = await request.post('/api/users', {
  name: 'John',
  email: '[email protected]',
})

// 带配置的请求
const data = await request.get('/api/data', {
  params: { page: 1, size: 10 },
  skipDedupe: true, // 跳过去重
  skipLoading: true, // 跳过 Loading
  skipErrorHandler: true, // 跳过错误处理
})

Loading 管理

import { loadingManager } from '@krysent/kite-core'

// 监听全局 Loading 状态
const unsubscribe = loadingManager.onChange(isLoading => {
  console.log('Loading:', isLoading)
  // 更新 UI 状态
})

// 取消监听
unsubscribe()

// 获取当前 Loading 状态
const isLoading = loadingManager.isLoading()

错误处理

import { request, BusinessError, ErrorCode } from '@krysent/kite-core'

try {
  const data = await request.get('/api/data')
} catch (error) {
  if (error instanceof BusinessError) {
    console.error('业务错误:', error.message)
    console.error('错误码:', error.code)
    console.error('错误类型:', error.errorCode)
  }
}

// 自定义错误处理
await request.post('/api/data', payload, {
  customErrorHandler: error => {
    // 自定义错误处理逻辑
    console.error('Custom error:', error)
  },
})

请求去重

默认情况下,相同的请求(method + url + params + data)会被自动去重:

// 第一个请求正常发送
const promise1 = request.get('/api/users')

// 第二个相同请求会被取消
const promise2 = request.get('/api/users') // 会被取消

// 跳过去重
const promise3 = request.get('/api/users', {
  skipDedupe: true, // 不会被去重
})

配置选项

| 选项 | 类型 | 默认值 | 说明 | | -------------------- | ---------- | ------- | --------------------- | | skipDedupe | boolean | false | 是否跳过请求去重 | | skipLoading | boolean | false | 是否跳过 Loading 计数 | | skipErrorHandler | boolean | false | 是否跳过错误处理 | | customErrorHandler | function | - | 自定义错误处理函数 |

响应数据格式

请求封装期望后端返回以下格式:

interface ResponseData<T> {
  code: number // 状态码,0 或 200 表示成功
  message: string // 错误消息
  data: T // 数据
  success?: boolean // 是否成功(可选)
}

创建自定义请求实例

import { createRequest } from '@krysent/kite-core'

const customRequest = createRequest({
  baseURL: 'https://api.example.com',
  timeout: 5000,
  headers: {
    'X-Custom-Header': 'value',
  },
})

// 使用自定义实例
const data = await customRequest.get('/api/data')