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

good-mock

v1.2.13

Published

好用的 Mock 数据模板

Readme

good-mock

npm version

简单好用的 数据 Mock 插件

安装

在项目根目录下安装

$ yarn add good-mock -D

使用

根目录:

根目录

在项目根目录下新建文件夹 mock 目录(可拷贝这个文件),在新建 data 目录和一个配置文件 config.js(文件名必选为 config.js) data (可多级目录和多个 js 或 ts 文件)中 .js.ts 中文件格式如下: 其中 mock/data中参数是用于设置数据 mock 接口,以 k-v 的方式进行设置,接口的 HTTP 方法通过在 key 中进行指定,支持的 HTTP 方法有:['GET', 'POST', 'HEAD', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH']

步骤一

mock/data/api.[tj]smock/data/user/api.[tj]s

module.exports = {
	// GET => method , /api/info/1 =>api path , 3000 => 数据返回时间,毫秒(ms),会覆盖配置的中 resTime
	"GET /api/info/1 3000": {
		name: "xxx"
	},

	"POST /api/info": {
		file: "xxxx"
	}
};

步骤二

/mock/config.js(或/mock/config.ts ) 配置文件

// mock 配置文件
module.exports = {
	host: "127.0.0.1", // host
	port: 1234, // 端口
	https: false, // 是否https 请求
	resTime: 600 // 全局数据返回时间,毫秒
};

步骤三

shell 中执行

nodemon --watch mock --exec ts-node ./node_modules/.bin/good-mock (window运行可能有问题)
or
nodemon --watch mock --exec ts-node ./node_modules/good-mock/lib/index.js

也可以在 package.json 中添加脚本执行

 "scripts": {
   "mock": "nodemon --watch mock --exec ts-node ./node_modules/good-mock/lib/index.js"
 }

end npm run mock

参数

/mock/config.js(或/mock/config.ts ) 中可以接受如下参数:

| 参数项 | 类型 | 是否可选 | 用途 | | :------ | :------ | :------- | :--------------------------------------- | | host | string | 是 | 设置数据 mock 服务地址,默认为 127.0.0.1 | | port | number | 是 | 设置数据 mock 服务端口,默认为 1234 | | https | boolean | 是 | 是否是 https (暂不可用) | | resTime | number | 是 | 全局请求后数据返回时间,毫秒,默认为 500 |

发布

提交版本

  1. 修订版本号:patch 不定时会进行日常 bugfix 更新。(如果有紧急的 bugfix,则任何时候都可发布)列:1.0.0 -> 1.0.1
npm run patch
  1. 次版本号:minor 一个 feature 或多个 feature 同时发布,列:1.0.0 -> 1.1.0
npm run minor
  1. 主版本号:major 含有破坏性更新和新特性,不在发布周期内,列:1.0.0 -> 2.0.0
npm run major

发布到 npm

npm run pub