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

jsdoc2configs

v1.1.1

Published

`jsdoc2configs` 是一个用于从 JSDoc 注释生成配置文件的库。它支持自定义模板、转换函数、分隔符和注释标签。

Readme

jsdoc2configs

jsdoc2configs 是一个用于从 JSDoc 注释生成配置文件的库。它支持自定义模板、转换函数、分隔符和注释标签。

功能特性

  • 从 JSDoc 注释生成配置文件:解析 JSDoc 注释,根据模板生成配置文件。

  • 自定义模板:使用自定义模板生成配置文件。

  • 自定义转换函数:使用自定义转换函数处理生成的配置内容。

  • 自定义分隔符:使用自定义分隔符替换模板中的占位符。

  • 自定义注释标签:使用自定义注释标签标记需要生成配置的代码块。

  • 支持 Glob 语法:使用 Glob 语法指定输入文件。

安装

bun add jsdoc2configs

使用方法

基本用法

假设我们有一个 .ts 文件

/**
 * @jsdoc2configs
 * 
 * @desc Sum of two numbers.
 * @export
 * @param {number} a - Number of one.
 * @param {number} b - Number of another.
 * @returns {number} a + b
 */
export function sum(a: number, b: number) {
   return a + b
}

接着我们创建一个 run.ts 文件:

import jsdoc2configs from 'jsdoc2configs'

jsdoc2configs({
  inputs: ['path/to/your/file.ts'],
  template: `{
    "desc": {{ desc }},
    "param": {{ param }},
    "returns": {{ returns }}
  }`,
  convertFunction: (docContent) => JSON.parse(docContent),
})
  .then(({ renderedList }) => console.log(renderedList))

生成后,我们可以从输出中看到日志:

[
  {
    desc: "Sum of two numbers.",
    param: [
      {
        type: "{number}",
        comment: "- Number of one.",
        paramName: "a",
        optional: false,
      }, {
        type: "{number}",
        comment: "- Number of another.",
        paramName: "b",
        optional: false,
      }
    ],
    returns: {
      type: "{number}",
      comment: "a + b",
    },
  }, {
    desc: "Diff of two numbers.",
    param: [
      {
        type: "{number}",
        comment: "- Number of one.",
        paramName: "a",
        optional: false,
      }, {
        type: "{number}",
        comment: "- Number of another.",
        paramName: "b",
        optional: false,
      }
    ],
    returns: {
      type: "{number}",
      comment: "a - b",
    },
  }
]

配置选项

jsdoc2configs(option) 接收一个 Jsdoc2ConfigsOptions 对象:

interface Jsdoc2ConfigsOptions {
  inputs: string[]; // 输入文件路径,支持 Glob 语法。
  template?: string; // 用于生成配置文件的模板。
  delimiter?: string; // 自定义分隔符,用于替换模板中的占位符,默认为 "{{}}"
  keyCommentTag?: string; // 自定义注释标签,用于标记需要生成配置的代码块,默认为 "jsdoc2configs"
  convertFunction?: (docContent: string) => any; // 自定义转换函数,用于处理生成的配置内容。
}

示例

完整的使用示例可以参考 测试用例

开发和构建

推荐使用 bun 进行开发和测试

bun test

由于目前 bun 并非 100% 支持 NodeJS 的 API,所以直接使用 bun build 会报错,因此该项目仍然使用 Rollup 进行构建。

yarn build # rollup -c

许可证

MIT