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

@nxapi/nxapi

v0.1.4

Published

@nxapi/nxapi

Readme

nxapi

这个库的功能是将类和类函数信息转换成 DSL,DSL 描述了函数携带的所有信息。下面将详细介绍

使用

安装

npm i @nxapi/nxapi -D

配置

在根目录配置 .nxapirc.js 文件,内容如下:

module.exports = {
  rootDir: 'src', //根目录
  ctrlDir: 'controllers', //需要转DSL目录
  outputDir: '__tmp__', //输出目录
  plugins: ['package'|function], //接受DSL和输出路径
};

执行

nxapi build|watch

插件 plugin 定义

import { DSLController } from '@nxapi/nxapi';

export default (controllerDsls: DSLController[], tmpRelativePath: string) => {
  //插件逻辑处理,处理该库转换的DSL
};

类和类函数定义

首先看下如何定义类和类函数。类必须继承类名为 BaseController 的类,所以这个基类可以自定义。然后添加描述信息。如下:

import { d } from '@nxapi/nxapi';

@d.controller.path('/v1')
export default class HelloController extends BaseController {
  @d.function.get('/hello')
  @d.function.description('接口描述')
  public hello(name: string): string {
    return 'hello ' + name;
  }
}

将上面信息转换成 DSL 如下:

{
  "fileFullPath": "/Users/xxx/workspace/xxxx/src/controllers/hello-controller.ts",
  "className": "HelloController",
  "classMethods": [
    {
      "classMethodName": "hello",
      "get": "'/hello'",
      "description": "'接口描述'",
      "req": { "fields": [{ "name": "name", "type": "string", "isArray": false }], "type": "params" },
      "dto": { "isArray": false, "type": "string" }
    }
  ],
  "path": "'/v1'"
}

函数详解

参数

参数数量为 1

  • 参数为基础类型或数组。将参数打包成一个对象,字段名就是参数名
  • 参数为自定义对象。将参数名丢掉,参数当成对象

参数数量大于 1

  • 将参数打包成一个对象,字段名就是参数名

返回类型

  • 返回类型没有限制

装饰器

这里装饰器没有处理逻辑,只是对类、函数、参数、返回类型的额外描述。在生成 DSL 的时候,将装饰器描述一起带出。例如:

// file
export class TestReq {
  @d.string.required()
  @d.string.max(10)
  @d.string.allow('v1', 'v2')
  @d.string.error(() => '错误描述')
  test: string;
}

//file
import { d } from '@nxapi/nxapi';
import { TestReq } from './req/test-req';

@d.controller.path('/v1')
export default class HelloController extends BaseController {
  @d.function.get('/hello')
  @d.function.description('接口描述')
  public hello(req: TestReq): string {
    return 'hello';
  }
}

将上面信息转换成 DSL 如下:

{
  "fileFullPath": "/Users/xxx/workspace/xxxx/src/controllers/hello-controller.ts",
  "className": "HelloController",
  "classMethods": [
    {
      "classMethodName": "hello",
      "get": "'/hello'",
      "description": "'接口描述'",
      "req": {
        "fields": [
          {
            "name": "test",
            "type": "string",
            "isArray": false,
            "required": true,
            "max": "10",
            "allow": ["'v1'", "'v2'"],
            "error": "() => '错误描述'"
          }
        ],
        "fileFullPath": "/Users/xxx/workspace/xxxx/src/controllers/req/test-req.ts",
        "type": "TestReq"
      },
      "dto": { "isArray": false, "type": "string" }
    }
  ],
  "path": "'/v1'"
}

装饰器类型总共有 8 中类型分别是 any、array、boolean、controller、function、number、object、string 使用方法很简单,不需详细介绍