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

ts-doc2

v1.0.26

Published

Generate api doc by annotations

Readme

ts-doc2

根据ts文件中的类和方法上下文进行ast分析并获取类名、类的注释、类中方法的注释、出参、入参的注释等元数据信息生成ts文件

灵感来以及部分方法来自https://github.com/hughfenghen/ts-rpc

使用方法

1.安装ts-doc2

> npm i ts-doc2 -D

2.建立一个的json配置文件,用于ts-doc2读取你的配置

tsConfigFilePath(必选)

tsconfig.json文件相对于process.cwd()的位置

例如:"./tsconfig.json"

scanDir(非必选)

需要扫描的文件夹范围;glob语法,如果不传的话默认会对process.cwd()下所有的ts文件进行扫描

例如:["demo/controller/*.ts"],会扫描process.cwd()下的demo/controller下的所有ts文件

outFilePath(非必选)

meta文件输出的位置以及名字

例如:"demo/meta.ts",会在process.cwd()下的demo文件夹生成一个名为meta.ts的元数据文件

3.在需要生成的类和方法前加上注释@tsDoc

interface IFavItems {
  //收藏ID
  id: number
  //类型 *可以是单行注释
  type: number
  /**
   * 封面 *可以是多行注释
   */
  cover: string
}

/**
 * @tsDoc
 * 用户相关controller
 */
class UserController {
  /**
   * @tsDoc
   * 获取用户信息
   */
  getUserInfo(
    //用户id
    uid: number,
    //性别
    gender: boolean,
    //是否是会员
    isVip?: boolean
  ): IFavItems {
    return {} as any
  }
}

4.在package.json新建一条script

"scripts": {
   "genDoc": "ts-doc2 -c ./ts-doc2.json",//这里的ts-doc2.json 是上一步建立的json文件的名字
}

5.运行刚刚建立的script命令

> npm run genDoc

6.生成成功~

/* eslint-disable */
export const meta = [
    {
      "className": "UserController",
      "classComments": ["用户相关controller"],
      "methods": [
        {
          "name": "getUserInfo",
          "methodComments": ["获取用户信息"],
          "decorators": [],
          "params": [
            {"name": "uid", "comments": ["//用户id"], "required": true, "type": "\"number\""},
            {"name": "gender", "comments": ["//性别"], "required": true, "type": " \"boolean\""},
            {"name": "isVip", "comments": ["//是否是会员"], "required": false, "type": " \"boolean\""}
          ],
          "returnType": "\n{\n  //收藏列表\n  \"fav\": [\n    {\n      //收藏ID\n      \"id\": 0,\n      //类型\n      \"type\": 0,\n      //封面\n      \"cover\": \"\"\n    }\n  ],\n  //用户id\n  \"uid\": 0,\n  //用户名\n  \"uname\": \"\"\n}\n"
        }
      ]
    }
  ]
;

额外内容

一个用于渲染上述元数据的前端项目 https://github.com/tohrux/ts-doc2-view