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

rocket-swap

v3.0.16

Published

<p align="center"> <img src="https://isee.weishi.qq.com/live/wesee-live/swaplogo.png" alt="swaplogo" width="300" /> </p>

Downloads

869

Readme

为什么要使用SWAP

如果你有以下场景

  • 开发web页面,苦苦等待后端调试
  • 苦恼在APP调试移动H5页面(why?你可能使用到JSBridge)
  • 要写很多非主业务和衍生文件进行单元测试
  • 你的mock api需要侵入关联业务 or 手动开关mock

不妨尝试接入 SWAP,可以帮助您解决以上的问题。

根据不权威调研

客观分析开发一个移动H5需求的时间(某视APP榜单):

  • 业务代码开发与调试:2D
  • 与后端联调:1D
  • 编写单元测试:2D(90%覆盖率)
  • 总时长:5D

使用了SWAP之后:

  • 业务代码开发与调试:1D
  • 与后端联调:0D
  • 编写单元测试:1D
  • 编写MockData: 0.5D
  • 总时长:2.5D

特性

  • 无侵入模拟API
  • 熟悉的Node Response用法
  • 支持jest,可以让你编写更少的单元测试
  • 中心化Mock Data
  • 支持JSBridge Mock

如何使用

注意事项
  • 需要在httpslocalhost 的域名中操作,自定义https域名可以利用whistle
  • webpack需要4.40.0以上版本
  • 如果使用webpack 5 需要额外引用 node-polyfill-webpack-plugin
1.安装依赖包
npm install rocket-swap
2.根据项目构建方案
  • 如果项目有使用webpack 4.40.0以上版本
    // webpack.config.js
    // const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');  // webpack 5 需要引入
    const SwapWebpackPlugin = require('rocket-swap/webpackPlugin');
    ...
    module.exports = {
      ...
      plugins: [
        // new NodePolyfillPlugin(); //webpack 5 需要引入
        new SwapWebpackPlugin();
      ]
    }
  • 非webpack项目,请执行cmd,把swapSW.js生成到项目public目录
    npx swap init <xxxxxxx>

    xxxxxxx 代表 public地址,如果是create-react-app,则如下

    npx swap init public
3.项目中引用
// src/index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
// 引入swap
if (process.env.NODE_ENV === 'development') {
  const swap = require('rocket-swap')
  const mockData = require('../mock')
  swap.swapInit({
    mockData
  })
}

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);
// mocker.js
module.exports = {
  'GET /list': (req, res, ctx) => {
    return res(
      ctx.status(200),
      ctx.json({
        code: '201',
      }),
    )
  }
}

展望

  • 云端API接入
  • 构建工具Plugin

Contributors

感谢大家的贡献: