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

service-api2ts

v1.0.1

Published

base swagger v2 ts API

Readme

service-api2ts

一个使用命令行执行api自动化构建维护工具,主要面对的痛点:

  1. typescript 对于api差异化的改动频繁造成的遗漏问题。
  2. 对于 api 服务多方改动引起的无效沟通过多问题。
  3. 前端目前对服务器 mock 自动化不足问题。

如何使用?

首先安装插件

npm i service-api2ts -D

编写配置文件,以下涉及目录路径均已项目根目录为相对路径

{
  // 远程/本地 api.json 路径,目前只支持swagger v2 与 yapi
  "originUrl": "",
  // "api.json的类型
  "originType": "SwaggerV2 | Yapi",
  // 请求远程 api.json 附带的参数,会被添加至请求body
  "originReqBody": {},
  // api库名称
  "name"?: "",
  // 本地api文件模板路径,只支持 .ts 文件
  "modsTemplatePath": "",
  // 输出文件路径
  "outDir": "",
  // 是否要生成mock文件
  "mocksDev": false,
  // 匹配相对应 path 的api执行mock生成
  "mocksModsReg": RegExp
}

编写modsTemplate文件,service-api2ts将api文件的生成规则交由用户自己实现,内部编译时会执行该ts文件,生成相对应的ts代码,写入文件。

import { StandardInterface } from 'service-api2ts'
// StandardInterface 带来如下信息
// StandardInterface.bodyParamsCode 为 api body中的参数类型/集合
// StandardInterface.paramsCode 为 api query 中的参数类型/集合,query本身的特殊性,一般不会是一个完整类型
// StandardInterface.formParamsCode 为 api formData 类型的参数集合
// StandardInterface.method api 请求 method
// StandardInterface.path api 请求路径
// StandardInterface.responseType api 返回类型

export default function (inter: StandardInterface) {
  const dataType = 混合 formParamsCode | paramsCode | bodyParamsCode 类型
  return `
    export default function (data: dataType) {
      return axios.${inter.method}<${inter.responseType}>('${inter.path}', data)
    }
  `
}

命令行执行生成文件

npx api2ts create 配置文件路径

执行结果

avatar

缺陷未解决

  1. 多人协作带来的分支不同,同步后导致类型不对。这个问题考虑限制更新范围来解决。
  2. mock不够灵活,毕竟按照简单数据类型来生成,对于数据字典等有上下映射关系的无能为力。
  3. 多数据源的管理能力较弱,还是需要使用多配置文件来处理。