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

ksc-mocker

v2.0.6

Published

koa 模拟接口服务

Downloads

63

Readme

ksc-mocker

koa 模拟接口服务 , 基于 koa , mockjs

install

npm install -D ksc-mocker

uninstall

npm uninstall ksc-mocker

usage

shell

 $> kmock -h

    Usage: kmock [options]

    Options:

      -V, --version        output the version number
      -S, --src [src]      glob模式使用引号包裹 , 逗号分隔 , 默认为 ./mock/**/*.js,!./node_modules/**/* (default: ./mock/**/*.js,!./node_modules/**/*)
      -W, --watch [watch]  设置监控文件改动 , 默认为 false (default: true)
      -P, --port [port]    设置启动端口 , 默认为 3500 (default: 3500)
      -H, --host [host]    这是启动host , 默认为 127.0.0.1 (default: 127.0.0.1)
      -h, --help           output usage information

例子

kmock -h
kmock -S "./test/**/*.js" -W

配置文件说明

  • JS 版
module.exports = [
    {
        path:"/kceapi",
        when:(request)=>{
            return true
        },
        method:'all' //默认get , `all`为特殊值,代表全部支持
        proxy:{
            target: 'https://kce.console.ksyun.com',
            secure: false
        } //proxy `http-proxy-middleware` 设置方法
    },
    {
        path:"/kceapi",
        when:({query})=>{
            return query.Action == 'QueryClusterSimpleList'
        },
        method:'get' //默认get , `all`为特殊值,代表全部支持
        response: {
            "RequestId": "188e4dc7-8632-4a87-a0d5-8b55c2d93ee3",
            "Data": {
                "ClusterList": [{
                    "ClusterId": "33ssxc444",
                    "ClusterName": "集群1",
                }]
            }
        }
    }
];
  • json 版本
[
    {
        "path":"/faker222",
        "response": {
            "array|1-10": ["Mock.js"],
            "foo": "Syntax Dem222",
            "nested": {
                "a": {
                    "b": {
                        "c": "Mock.js"
                    }
                }
            },
            "absolutePath": "@/foo @/nested/a/b/c"
        }
    }
]

匹配规则

  1. 优先根据 path 全路径匹配或模糊路径匹配 、method 请求方法 ,匹配出有效命中集合
  2. 通过 when 函数判断最后的命中规则项目 , 作为命中规则 默认 when 全部返回生效
  3. 规则命中后如是proxy则代理到指定的服务 , 如是responsemock 数据返回

path > path-to-regexp | when > last | (proxy ? proxy : mock)

书写配置方法

  • pathmethod必填
  • when选填,接受requestctx两个参数,根据返回结果匹配命中规则
  • proxy选填,语法参照http-proxy-middleware
  • response返回结果,需自己mock数据时理论上必填,(当配置proxy时,将代理到指定服务器,response参数不写)
  • 当命中规则项目有很多时,返回第一个成功匹配的数据(因此,第一条数据习惯性可配置为全局性的proxy,其余数据按需求写mock)

run

查看 package.json