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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mjson2ts

v0.0.4

Published

swagger转为ts

Downloads

10

Readme

安装

yarn add mjson2ts -D 或者 npm install mjson2ts -D

使用

根目录下新建tsg1.js,执行 yarn tsg1 或者 npm run tsg1

如果想要自定义文件名,可加上参数, --c 后跟上文件名即可

配置

module.exports = {
  // url: 可以是远程swagger json,也可以是本地json
  url: 'https://petstore.swagger.io/v2/swagger.json',
  // url: './test.json',

  // 输出文件的根目录
  output: './src/api',

  // 多个源
  // origins: [
  //   {
  //     name: 'self',
  //     url: 'https://petstore.swagger.io/v2/swagger.json',
  //   },
  //   {
  //     name: 'pet',
  //     url: 'https://petstore.swagger.io/v2/swagger.json',
  //   }
  // ],

  // 非必须, staticPath 为本地的ajax 封装文件,可在执行命令后移动到 ouput 声明的文件夹下。
  // staticPath: './request.ts',

  /* ajaxImportPath 项目中的 ajax request 文件的访问路径
  * ajaxImportPath 优先级高于 staticPath
  */
  // ajaxImportPath: '@http/request',
}

ajax 暴露的应该是一个对象

  1. 应该有 get, post, put, delete方法的实现
  2. return 之后应该返回 *** Promise<T> ***
  3. 可参考下方的代码,配置只填写 url 和 output 时会自动复制一个request.ts到 output 目录下
export default {
  get<T>(url: string, params) {
    const [reqUrl, option] = interceptRequest(url, params)
    option.method = 'get'
    return fetch(reqUrl, option).then<T>(interceptResponse)
  },

  post<T>(url: string, params) {
    const [reqUrl, option] = interceptRequest(url, params)
    option.method = 'post'
    return fetch(reqUrl, option).then<T>(interceptResponse)
  },

  put<T>(url: string, params) {
    const [reqUrl, option] = interceptRequest(url, params)
    option.method = 'put'
    return fetch(reqUrl, option).then<T>(interceptResponse)
  },

  delete<T>(url: string, params) {
    const [reqUrl, option] = interceptRequest(url, params)
    option.method = 'delete'
    return fetch(reqUrl, option).then<T>(interceptResponse)
  },
}

有问题可以提issue

  1. 目前无法处理动态路由,如/order/:id/putImage这样的形式,
  2. /order/:id 这样的还是可以处理的