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

proxymock-cli

v0.1.2

Published

proxymock-cli

Downloads

18

Readme

proxymock-cli

proxymock-cli

how to use?

  • 安装 yarn global add proxymock-linpm install proxymock-cli -g

  • 执行 proxymock -d <mock data directory> [-s] [-l <log level>]

  -d: mock数据文件存放目录, <必填>
  -s: 是否设置系统代理为proxymock代理服务器的ip和端口, [选填]
  -l: 日志级别, 默认级别`info`, 可选级别项: `debug`、`inf`o、`warn`、`error`, [选填]
  • 日志打印目录为操作系统登录用户目录下的.proxymock文件夹, windows系统如 C:\Users\your-pc-name\.proxymock

mock文件指令规则

  • 以单行注释语法 // 作为mock文件规则的指令, 指令不支持多行注释语法 /**/

  • // proxymock: [^] <GET|POST|PUT|DELETE> <url> 此指令必选; 指令中<>表示必填, []表示选填, |表示多选一

  • // proxymock-disable: [true|false] 此指令可选

  • <url> 部分支持正则表达式

mock文件示例

  // proxymock: ^ GET https://weather.qq.com/api/shanghai.do
  // proxymock-disable: false

  module.exports = {
    desc: '艳阳当空、烈日炎炎',
    temperature: 38,
    feeling: 'hot'
  }
  // proxymock: GET http://www.weather.cn/api

  /**
   * req: 可用 { query, params, body, header } 等参数作为条件导出不同mock数据
   * res: 可用 .json(), .end() 等方法回传mock数据
   */
  module.exports = async function(req, res, rawData) {
    await new Promise(resolve => setTimeout(() => resolve(), 3000)); // 模拟请求延迟3秒

    if (req.query.type === 'hot') {
      return {
        desc: '艳阳当空、烈日炎炎',
        temperature: 38,
        feeling: 'hot'
      };
    }
    
    if (req.query.type === 'cold') {
      res.json({
        desc: '大雪纷飞、寒风刺骨',
        temperature: -25,
        feeling: 'cold'
      });
    }
  };
  // proxymock: GET /weather\.[a-z]{2}\.com\/api/
  // proxymock-disable: false
  // 正则示例

  module.exports = async function(req, res, rawData) {
    return { feeling: 'cool', temperature: 22, desc: '秋高气爽' };
  };

运行截图

参考资料

nodejs动态加载代码