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

lib-mock-server

v1.0.10

Published

基于mockjs+json描述文件的模拟数据,支持RESTful风格

Downloads

11

Readme

  1. 使用规范
    npm install lib-mock-server --save-dev
    //mock.server.js
    const mockServer = require('lib-mock-server')
    const server =  mockServer({...})
start server: node mock.server.js
  • config.js 配置说明:

| 字段 | 说明 | | ----------- | --------------------------------------------------------------------------------------------------------- | | baseURL | 请求接口的 baseURL ,mock 会将接口的 baseURL 去掉,再去寻找 mock 数据源 | | proxy | 后备接口地址,如果 mock 没有数据源,则会继续请求该接口地址 ,参考 http-proxy createProxyServer 第三个参数 | | port | 服务启动端口,默认为 8510 | | contentType | 数据返回格式,默认为 application/json;utf-8 | | sleep | 模拟请求延时,默认为 ()=> 0.1 | | mockDir | 数据源目录,服务将在此目录下匹配数据 |

  1. json 文件命名规范

文件命名以接口地址 baseurl 后,第一个斜杠前名称为准

  1. json 模拟数据描述规范,基于 MockJS
  • key 规范

  • 规范:[请求方法类型:][接口地址][正则?]

  • 第一部分为请求类型,支持 get post delete put 注意以冒号结尾

  • 第二部分为接口地址,如果请求接口为/baseurl/user/list 则 key 应该为 get:user/list

  • 第三部分为正则,为了动态匹配接口地址 例如删除某个用户 /baseurl/user/:userId ,则应该为 delete:user/\\d{10}

  • value 规范

  • value 规范直接参考 mockjs 即可

  • 增强了在正则表达式 rule,在 key 中添加 |regexp 即可,例如生成一个随机电话号码:{"phone|regexp":"183[2-9]{4}8888"},中间 4 位数将随机生成