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

mock-convert

v1.2.1

Published

convert interface data to mock data

Downloads

19

Readme

mock convert

将idoc上的接口数据转换为mock数据

安装

npm i mock-convert --save-dev

使用

写好配置文件,然后执行,配置文件参考下一节

mock-convert -c config/config.js;

配置文件

config.js

module.exports = {
    projectJsonUrl: "http://api.demo", // 项目文档接口地址,必须
    outOpt: {
        outPath: "mock/data.js", // 生成mock文件输出的路径,必须
        singleFile: true, // 生成单个文件,默认为false
        fileNames: {
            '登录': 'login',
            '行情': 'market',
        } // 文件名
    }
    parseOpt: [ // 可选配置
        {
            dataType: "string", // 参数类型,支持多个参数类型,类型之间用,分隔开
            identifier: "price", // 参数变量名
            ignoreCase: true, // 匹配时候是否忽略大小写,匹配内容为identifier的值
            fullMatch: false, // 全字匹配,匹配内容为identifier的值
            target: '\"$identifier$\|3000-5000.1-2\": 3000', // 生成目标,identifier为占位符,在转换过程中会替换为identifier的值
        },
        {
            dataType: "int,string",
            identifier: "retcode",
            ignoreCase: true,
            fullMatch: true,
            target: 'retcode: 200'
        },
    ]
}

在可选配置中,可以对转换做定制化操作:

{
    dataType: "string",
    id: 49384,
    identifier: "buyPrice",
    isNecessary: 1,
    mock: "",
    name: "买入价",
    parameterList: [ ],
    remark: "精确到小数点2位 没有有效行情下是0",
    validator: ""
},
// 匹配到第一个规则,配置中$identifier$为占位符,实际使用中会替换为identifier的值,这里最终转换的结果为:"buyPrice|3000-5000.1-2": 3000
{
    dataType: "string",
    id: 49024,
    identifier: "retcode",
    isNecessary: 1,
    mock: "",
    name: "返回码",
    parameterList: [ ],
    remark: "200为成功,错误对应相应的错误代码 9011(交易密码错误,登录失败) 9018(账号或密码错误,无密码剩余次数记录)",
    validator: ""
}
// dataType支持多种数据类型,这里匹配到第二个规则,会转换为: retcode: 200

mock规则

mock规则可参考 http://mockjs.com/