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

egg-fancy-decorator

v1.0.7

Published

Decorator support plugin for egg framework

Readme

egg-fancy-decorator

NPM version Test coverage npm download

Some useful decorator for egg framework

  • @ResponseBody: Use like @ResponseBody in spring-boot
  • @ResponseJson: Similar @RequestBody, will convert response to format json
  • @RequestMapping: Use like @RequestMapping in spring-boot
  • @RequestParam: Use like @RequestParam in spring-boot
  • @RequestQuery: Use for get parameter in query
  • @RequestBody: Use for get parameter in post body

Install

$ npm i egg-fancy-decorator --save

Configuration

  • Modify tsconfig.json, enable decorates for typescript
{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}
  • Modify {app_root}/config/plugin.js
// {app_root}/config/plugin.js
exports.fancyDecorator = {
  enable: true,
  package: 'egg-fancy-decorator',
};

Example

Orignal egg router & controller useage:

// router.ts
import { Application } from 'egg';

export default (app: Application) => {
  const { controller, router } = app;
  router.get('/api/project/list', controller.project.list);
  router.post('/api/project/find', controller.project.find);
  router.post('/api/project/find2', controller.project.find);
};
// controller/test.ts
import { Controller } from 'egg';

export default class TestController extends Controller {
  public async list() {
    const { ctx } = this;
    const { query } = ctx;
    ctx.body = await ctx.service.project.list({
      pageSize: query.pageSize,
      page: query.page,
    });
  }

  public find() {
    const { ctx } = this;
    const { body } = ctx;
    const { keyword } = body;
    console.log(keyword);
    ctx.body = 'test find ' + ctx.request.href;
  }
}

A simple useage with fancy-decorator plugin decorator (like spring-boot 😀):

// controller/test.ts
// if you use the RequestMapping & ResponseBody, the router config in router.js can be omitted.
import { Controller } from 'egg';
import {
  RequestMapping,
  ResponseBody,
  RequestMethod,
  RequestParam,
  RequestQuery,
  RequestBody,
} from 'egg-fancy-decorator';

export default class TestController extends Controller {
  /**
   * A simpe way to define a router path for a controller method
   */
  @RequestMapping('/api/project/list')
  @ResponseBody
  public async list(
    @RequestParam('pageSize') pageSize: string,
    @RequestParam('page') page: string,
    @RequestParam({ value: 'pageSize', valueType: 'number' }) pageSizeNum: number, // Cast to number
    @RequestQuery() query: any, // Get all query parameters
  ) {
    const { ctx } = this;
    console.log(query);
    return await ctx.service.project.list({ pageSize, page });
  }

  /**
   * You can define multiple router path once
   * set the method for request method and if the method is omitted, default method is GET.
   */
  @RequestMapping({ value: ['/api/project/find', '/api/project/find2'], method: RequestMethod.POST })
  @ResponseBody
  public find(@RequestParam('keyword') keyword: string, @RequestBody() body: any) {
    console.log(keyword);
    console.log('post body:', body);
    const { ctx } = this;
    return 'test find ' + ctx.request.href;
  }
}

Questions & Suggestions

Please open an issue here.

License

MIT