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

icinfo-api-generator

v1.1.4

Published

解析后端的微服务api文档,自动生成所需要的接口函数(TS格式的)

Downloads

8

Readme

api自动化生成代码工具

解析后端的微服务api文档,自动生成所需要的接口函数(TS格式的)

引入的命令

npm i icinfo-api-generator

基本用法案例

在需要的项目中创建一个文件,比如 api.js

const axios = require('axios')
const { generate } = require('icinfo-api-generator')

async function main() {
    const apis = [
        'http://api.fed.icinfo.co/zzk/dtcenter/dt-qualities/develop/api.json',
    ]
    apis.forEach(async url => {
        const result = await axios(url)

        generate(result.data, {
            // mockDir: 'src/mock/data',
            tsDir: 'src/services',
            merge: true,
            request: 'http.request',
            prepend: `
import { ExAxiosRequestConfig } from 'icinfo-request'
import http from "@/scripts/http"`,
            optionsType: 'ExAxiosRequestConfig',
            dataDescription: '要提交给服务器的数据',
            optionsDescription: '附加选项',
            newLine: '\n',
        })

        // eslint-disable-next-line no-console
        console.log('已成功生成:', url.replace(/\/api\.json$/, ''))
    })
}

main()

同时在package.json配置scripts

"api": "node api.js"

执行方法为

npm run api

可配置的参数

| 名称 | 类型 | 是否必填 | 说明 | 默认值 | 备注 | |--------------------|-------------------|----------|---------------------------------------------------------|----------|------| | getMockData | function | 否 | 自定义个别字段的模拟数据 | - | - | | mockCount | function | 否 | 自定义个别字段的模拟个数 | - | - | | mockDir | string | 否 | 模拟数据文件夹地址 | - | - | | merge | boolean | 否 | 是否合并已有的模拟数据 | - | - | | mockDepth | number | 否 | 嵌套对象的最多模拟次数 | - | - | | mockPrefix | string | 否 | 模拟数据的前缀 | - | - | | tsDir | string | 否 | 接口文件夹地址 | - | - | | docFile | string | 否 | 生成的文档文件名 | - | - | | prepend | string | 否 | 模块前追加的内容 | - | - | | optionsType | string | 否 | 选项的类型 | - | - | | dataDescription | string | 否 | 数据的描述 | - | - | | optionsDescription | string | 否 | 附加选项的描述 | - | - | | request | string | 否 | 发起请求接口名 | - | - | | newLine | string | 否 | 使用的换行符 | - | - | | apiType | 'jquery'|'axios' | 否 | 参数配置的类型, 默认为jquery.ajax的方案,可选axios方案 | 'jquery' | - | | scriptType | 'ts'|'js' | 否 | 脚本类型,默认生成ts类型,可选js类型 | 'ts' | - | | include | string[] | 否 | 只有名称匹配的api全路径才会被生成 | - | - |

更新

2024-03-19

新增生成枚举值