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 🙏

© 2025 – Pkg Stats / Ryan Hefner

como-validate-ratelimit

v1.4.0

Published

This is a midway component sample

Readme

基于midwayjs 实现的基本项目组件

一、访问限流组件

  • 使用示例 在任意类的控制器中使用中件间RateLimitMiddleware 加入即可
  • 在任意对外的方法中使用中间件也可以
//管理员控制器
@Controller("AdminUser",{middleware:[RateLimitMiddleware]})
@UseGuard([AdminGuard,RouteGuard])
export class AdminUserController extends BaseController {}
  • 在配置项中加入限流配置(config.default.ts
//限流 以下配置为每秒中单个IP只能通过10个访问 具体情况可根据项目配置
limiter: {
	//限流次数
	points: (Number(process.env.APP_LIMITER ?? 10)),
	//时间 秒
	duration: 1
} as IRateLimiterOptions,

二、登录守卫组件

  • 在控制器中加入代码
@UseGuard([AminGuard])
  • 在配置项中加入限流配置(config.default.ts
HeaderUserKey:{
	//管理员请求头的key 从请求头中获取token下标的名称
	adminTokenKey?:string
	//web端获取请求头的key 从请求头中获取token下标的名称
	webTokenKey?:string
	//管理员获取名称 从请求头中获取的下标名称
	adminUser?:string
	//前端用户获取名称 从请求头中获取的下标名称
	webUser?:string
}
  • 继续守卫的基本类 示例
//管理员登录守卫
@Guard()
export class AdminGuard extends AppUserGuard implements IGuard<Context> {


    curClient: string = 'admin';

    /**
     * 实现路由拦截功能
     * @param ctx 
     * @param supplierClz 
     * @param methodName 
     * @returns 
     */
    async canActivate(ctx: Context, supplierClz: new (...args: any[]) => any, methodName: string): Promise<boolean> {
        if(!this.userService) {
            this.userService = await ctx.requestContext.getAsync(AdminUserService);
        }
        return super.canActivate(ctx,supplierClz,methodName);
    }

}

三、后端页面动态渲染组件

1、数据列表渲染组件
//提供以下类
//WebTable WebTableColumn WebTableHeader WebTableConfig WebTablePagination

//提供装饰器
//@TableColumn @SearchColumn
//提供渲染方法拿到列
//this.WebTableColumns(参数是有TableColumn的类) 即可得到需要展示的列
//thsi.WebSearchColumns(参数是有TableColumn的类)

2、表单渲染组件

//提供以下类
//WebForm WebFormColumnItem

//提供一个装饰器
//@FormColumn
//提供渲染方法拿到列
//this.WebFormColumns(参数是有TableColumn的类,data:{对象数据},list?:{可选项列表}) 即可得到需要填写的表单

四、常用工具类

  • 常用工具类 ComoAppUtils 提供的方法很多 如格式化数组处理 文本处理 身份证号码处理等等
  • 使用示例 更新使用 请查看源码
ComoAppUtils.Ins.Time()

五、自定义快速验证组件

//提供以下类
//ComoValidatePipe ComoQuickValidatePipe QuickValidateUtils ComoValidateOccasion ComoValidatorError

//提供一个装饰器
//@ComoValidate
//提供渲染方法拿到列
//this.ApiTransform(验证方法,待验证的数据) 即可得到验证后的数据

六、图像处理组件

  • 图像处理组件
//提供一个类 是基于sharp包封装后的 ComoAppImage