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 🙏

© 2025 – Pkg Stats / Ryan Hefner

js2dt

v0.2.5

Published

a lib for js generate d.ts with jsdoc

Downloads

8

Readme

js2dt

github | npm

通过AST语法树和jsdoc注释解析将JavaScript代码转换成对应的Typescript的Type文件,也就是.js转.d.ts文件。由于js和ts的语法区别,并不保证可以完美转换。

状态

status:Alpha

安装

通过npm全局安装:

npm install -g js2dt

作为babel插件本地安装:

npm install --save-dev js2dt

安装完成功查看版本确定是否安装成功:

js2dt -v

使用

一般使用:

js2dt --src ./test.js

配置babel插件:

// babel.config.json

"plugins": [
    ["./node_modules/js2dt", {
      "overwrite": true
    }]
  ]

配合webpack使用:

// webpack.config.js

rules: [
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env'],
            plugins: [
              ["./node_modules/js2dt", {
                "overwrite": true,
                "outdir": 'dist/type',
                "publicdir": ''
              }]
            ]
          }
        }
      }
    ]

命令配置项:

配置项|简写|作用|备注 ---|---|---|--- --src [path]|-s|生成指定path路径的js文件的类型文件|- --deep | \ | 对文件引用的文件也生成类型文件 | 会排除引用的库 --overwrite| -o | 生成时覆盖已存在的类型文件 | -

插件配置项:

配置项|类型|作用|备注 ---|---|---|--- "overwrite"| boolean | 是否覆盖已存在的d.ts文件 | - "outdir"| string | 输出d.ts文件的目录 | 不写则会默认在当前目录 "publicdir" | string| 源文件的公共路径 | 会去除原路径前的公共路径

注意项:

  1. 必须指定文件路径。
  2. d.ts文件会生成在js文件相同目录下
  3. 对部分js语法解析可能会有问题。

更新计划

  1. 对导出语句增加支持 √
  2. 对相对路径导入语句增加支持 √
  3. 增加类型推断能力,不完全依赖于jsdoc

无法解析的语法

  1. ES5中类的写法
  2. 声明类后为类添加属性