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

@tosee/misc

v5.0.10

Published

Framework based on Koa and Typescript

Readme

Open in Visual Studio Code Build Status codecov NPM version

Misc

基于Koa与Typescript构建的框架

快速开始

  1. 安装命令行工具
npm i @tosee/misc-cli -g
  1. 初始化项目并运行
mkdir project
misc new ./project
cd project
npm run dev

配置项

Misc继承自Koa,实例化Misc时可以传入不同的参数来配置Koa实例,Misc自带koa-bodyparser,@koa/cors依赖,可以通过不同的配置来实现不同的功能,具体的参数细节查看API

keys

Koa 的 cookie 签名秘钥

beforeall

中间件数组,Misc会使用koa-compose组合数组中的中间件,这些中间处于koa-bodyparser,@koa/cors之后(如果有配置的话),routerpath目录中的各路由之前。

routerpath

Misc会加载该配置目录及其子目录下的所有ts文件,并获取它们的默认导出(export default),如果是koa-router实例(使用@Controller装饰器)则Misc会加载这些实例,默认路径src/router

body

koa-bodyparser配置选项,参照koa-bodyparser

protocol(必须)

可选 http 或 https,选择 https 时则必须配置 tls 选项。

tls

https 配置,详见https 参数

cors

跨域配置,使用@koa/cors,参照@koa/cors

port(必须)

监听端口号。

装饰器

@Controller

路由类装饰器,实例化类时转化为一个koa-router实例,作用类似于prefix,例:

@Controller('/hello');
class Test{

}

@GET

路由方法装饰器,与@Controller配合,实现一个 get 方法的路由,例:

@Controller('/hello');
class Test{
  @GET('/test')
  async test(){
    return 'hello world';
  }
}

@POST

路由方法装饰器,与@Controller配合,实现一个 post 方法的路由,例:

@Controller('/hello');
class Test{
  @POST('/test')
  async test(@Body body){
    return body;
  }
}

@PUT

路由方法装饰器,与@Controller配合,实现一个 put 方法的路由,例:

@Controller('/hello');
class Test{
  @PUT('/test')
  async test(){

  }
}

@DELETE

路由方法装饰器,与@Controller配合,实现一个 delete 方法的路由,例:

@Controller('/hello');
class Test{
  @DELETE('/test')
  async test(){

  }
}

@Body

参数装饰器,配合@POST,@GET,@PUT,@DELETE等方法装饰器时可以获取请求参数,该装饰器默认值为ctx.request.body,例:

@POST('/test')
async test(@Body body){
    return body;
}

@Query

参数装饰器,配合@POST,@GET,@PUT,@DELETE等方法装饰器时可以获取请求参数,该装饰器默认值为ctx.request.query,例:

@GET('/test')
async test(@Query query){
    return query;
}

@Headers

参数装饰器,配合@POST,@GET,@PUT,@DELETE等方法装饰器时可以获取请求参数,该装饰器默认值为ctx.request.headers,例:

@GET('/test')
async test(@Headers headers){
    return headers;
}

@Headers

参数装饰器,配合@POST,@GET,@PUT,@DELETE等方法装饰器时可以获取请求参数,该装饰器默认值为ctx.params,例:

@GET('/test/:id')
async test(@Params params){
    return params.id;
}

@Ctx

参数装饰器,配合@POST,@GET,@PUT,@DELETE等方法装饰器时可以获取请求参数,该装饰器默认值为ctx,例:

@GET('/test/:id')
async test(@Ctx ctx){
    return ctx.params.id;
}

@Validate

参数验证装饰器,使用class-validator实现,传入 schema 即可完成校验,支持自定义错误处理。

使用该装饰器后,参数装饰器获取的参数是经过该装饰器转换过后的参数(例如schema中包含Transform之类的功能),需要获取原始数据可以使用@Ctx装饰器获取koa的Context。

export class Login {
	/**
	 * username describe
	 */
	@IsString()
	username: string;

  /**
	 * password describe
	 */
	@IsString()
	password: string;
}

@Controller('/hello');
class Test{
  @Autowired()
  UserService:UserService

  @GET('/test)
  @Validate({schema:Login,error:(errors)=>{
    throw new Error(`${errors.map(error=>Object.value(error.constraints))}`);
  }})
  async test(@Query query){
    return query;
  }
}

工具

logger

打印信息,分为 error,info,和 succuess,带时间戳和不同颜色

import {logger} from '@tosee/misc'

logger.info("hello world");
app.use(logger.Middleware()); //在后续中间件中的logger打印会带上唯一id,参考@tosee/log

扩展

@tosee/config加载配置文件使用@Value装饰器注入

@tosee/util@Before,@After,@Around,@Catch,@Autowired,@Schedule等工具装饰器

@tosee/busboybusboy的封装,直接处理formdata文件流无临时文件,提供装饰器,中间件与自定义方式

@tosee/log支持RequestID与自定义格式的日志库