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

yapi-gen-js-code

v0.0.1

Published

根据 YApi 的接口定义生成 javascript 的请求函数,目前内置了 axios 请求模板

Downloads

2

Readme

yapi-gen-js-code

根据 YApi 的接口定义生成 javascript 的请求函数,目前内置了 axios 请求模板

安装

npm i -g yapi-gen-js-code

使用

1.首先需要创建 yapi-gen.config.js 配置文件,如下所示:

module.exports = {
  server: 'http://127.0.0.1:3000',
  token: '1f048e410bc22208297dec1113136cda58306d28fb0fa819652e659b16764be6',
  categoryId: 323
}

2.在当前目前执行 yapi-gen-js-code

yapi-gen-js-code

执行完成后,即可生成 yapi-gen-js-code.js 请求文件

可参考该 demo

yapi-gen.config.js配置项说明

| name | 类型 | 默认值 | 描述信息 |
| ---- | --- | --- | ---- | | server | String | - | 服务器地址,比如: http://yapi.demo.qunar.com | | token | String | - | 项目token |
| dist | String | - | 生成文件路径 |
| template | String Or Function | axios | 模板名,目前仅内置了 axios 模板,自定义请查看下面文档 | | globalCode | String |const axios = require('axios'); | 全局代码,会注入到最前面 |
| methodName | Function | 请参考源码 | 方法名生成函数,一般无需改动 | | categoryId | String | - | 项目分类id, 填写后只生成某个分类下的接口,默认生成该项目所有接口请求代码 | | enableValidte | Boolean | true| 是否开启参数验证,默认是开启的,需要引入 ava 依赖|

自定义模板

自定义模板就是写一个函数,返回一个 request 函数片段,接收两个参数,第一个 baseinfo,包含了请求 url, method, 请求参数等

{
  template: function(){
    return `function request(baseinfo, options = {}){
        let params = baseinfo.params;

        options = Object.assign({}, {
          url: baseinfo.url,
          method: baseinfo.method,
          data: params
        }, options)

        if(checkRequestParams && typeof checkRequestParams === 'function'){
          checkRequestParams(interfaceData ,params)
        }

        return axios(options)
      }`
  }
}