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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kxgo/easy-mock

v0.1.4

Published

easy mock data with easy config, support customize middleware

Readme

@kxgo/easy-mock

easy-mock只需一些简单的配置就可以轻松mock数据

安装


npm i @kxgo/easy-mock
or
yarn add @kxgo/easy-mock

使用


const path = require('path')
const easyMock = require('@kxgo/easy-mock')

new easyMock({
  // 请传递完整的配置文件路径进去,服务是会自动刷新
  path: path.resolve(__dirname, 'xxxx.js')
})

配置文件的例子

// xxxx.js
module.exports = {
  // common选项不是必须, 内置的配置如下,当然你也可以更改
  common: {
    // mock服务的默认端口,如果端口被占用,会换一个
    port: 8018,
    // 如果你想看一下ajax的loading效果,该配置项可以设置接口的返回延迟
    timeout: 500,
    // 如果你想看一下接口请求失败的效果,将rate设置成0就可以了,rate取值范围0~1,代表成功的概率
    rate: 1,
    // mock属性为false的话可以关闭掉mock服务
    mock: true,
    // 是否打印调试信息
    debug: false
  },
  // api...,可以不用写全,写最后一个就好
  'getList': {
    code: 0,
    'data|5': [{
      'uid|1000-99999': 999,
      'name': '@cname'
    }],
    result: true
  },
  '/pkApi/getPerson': {
    code: 0,
    'data|5': [{
      'name': '@cname'
    }],
    result: true
  },
  '/pkApi/getOther': {
    code: 0,
    'data|5': [{
      'name': '@cname'
    }],
    result: true
  }
}

服务启动后,打开http://127.0.0.1:8018/pkApi/getPerson就可以看到mock的数据了!

本地debug

npm i kxg -g
npm i nodemon -g

npm run dev

发布

npm i standard-version -g
npm run pub

Q&A


1 怎么去mock jsonp

在链接后面传callback参数就好了

2 怎么去mock数据

参考mock rule

3 怎么去处理更复杂的场景,我想要自定义数据返回
module.exports = {
  ...
  ['/pkApi/getOther'] (req, res) {
    const query = req.query
    // 可以自己写处理逻辑
    return {}
  }
  ...
}

get类型的请求可以通过req.query去获取参数

post类型的请求可以通过req.body去获取参数

issues


issue list

changelog

changelog