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

@esouyun/common

v1.0.0

Published

Common utilities and base classes for NestJS framework, including base controllers, services, interceptors, filters, and exception handlers

Readme

@esouyun/common

简介

@esouyun/common 是 NestJS 框架的通用工具库,提供基础控制器、服务、拦截器、过滤器和异常处理等常用功能。

特性

  • 基础控制器和服务类,简化 CRUD 操作
  • 统一的响应拦截器,格式化 API 响应
  • 全局异常过滤器,统一错误处理
  • 日志拦截器,自动记录请求日志
  • 超时拦截器,防止请求超时
  • 业务异常类,便于处理业务错误
  • 工具函数:加密、格式化等
  • 完整的 TypeScript 类型支持

安装

pnpm add @esouyun/common

快速开始

使用基础控制器和服务

import { Controller } from '@nestjs/common'
import { BaseController } from '@esouyun/common'
import { BaseService } from '@esouyun/common'

// 定义服务
class UserService extends BaseService<User, PrismaDelegate> {
  // 继承基础 CRUD 方法
}

// 定义控制器
@Controller('users')
export class UserController extends BaseController<UserService> {
  constructor(service: UserService) {
    super(service)
  }
}

使用拦截器

import { Module } from '@nestjs/common'
import { APP_INTERCEPTOR } from '@nestjs/core'
import { TransformInterceptor, LoggingInterceptor, TimeoutInterceptor } from '@esouyun/common'

@Module({
  providers: [
    {
      provide: APP_INTERCEPTOR,
      useClass: TransformInterceptor,
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: LoggingInterceptor,
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: TimeoutInterceptor,
    },
  ],
})
export class AppModule {}

使用全局异常过滤器

import { Module } from '@nestjs/common'
import { APP_FILTER } from '@nestjs/core'
import { AllExceptionsFilter } from '@esouyun/common'

@Module({
  providers: [
    {
      provide: APP_FILTER,
      useClass: AllExceptionsFilter,
    },
  ],
})
export class AppModule {}

使用业务异常

import { BusinessException } from '@esouyun/common'
import { API_CODE } from '@esouyun/common'

throw new BusinessException(API_CODE.ERROR, '操作失败')

使用工具函数

import { hashPassword, comparePassword, formatObject } from '@esouyun/common'

// 加密密码
const hashed = await hashPassword('password123')

// 验证密码
const isValid = await comparePassword('password123', hashed)

// 格式化对象
const formatted = formatObject({ name: 'test', age: 18 })

API 参考

BaseController

基础控制器类,提供通用的 CRUD 操作方法。

BaseService

基础服务类,提供通用的数据操作方法。

Interceptors

  • TransformInterceptor - 响应转换拦截器
  • LoggingInterceptor - 日志拦截器
  • TimeoutInterceptor - 超时拦截器

Filters

  • AllExceptionsFilter - 全局异常过滤器

Exceptions

  • BusinessException - 业务异常类

Utils

  • hashPassword - 密码加密
  • comparePassword - 密码验证
  • formatObject - 对象格式化

贡献

欢迎贡献代码、报告问题或提出建议。

许可证

MIT