1.1.6 • Published 5 years ago

ts-decorate v1.1.6

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

Install

npm i ts-decorate

How to use ?

  import Koa from 'koa'
  import TsRouter from 'ts-decorate'
  const app = new Koa()
  app.use({
    cwd: path.resolve(__dirname, 'controllers'),
    reg: './*.js',
    prefix: '/view'
  })

  cwd: 路由类所在目录
  reg: glob模块查找文件的匹配模式
  prefix: 所有路由的前缀, 可以省略

API

  • Class decorator

     import { Base } from 'ts-decorate'
    
     @Base('/xx')
     export default class xx{}
    
     设置当前类下的所有路由前缀; 可以省略
  • Method decorator

       import { GET, POST } from 'ts-decorate'
        
       export default class xx{
         
         @GET('/xx')
         async xxxx(){
           return {code: 200, data:xx, msg: xx}
         }
     
         @POST('/xx')
         async xxxx(){}
       }
  • Params decorator

     // 字符串形式
     @GET(xxx)
     getInfo(@params('name title') name: string, title: string, ctx, next){}
     
     // 多修饰形式
     @GET(xxx)
     getInfo(
       @params('name') name: string, 
       @params('title) title: string,
       ctx, next
     ){}
    
     ctx, next 这两个参数选传
1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago