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

nether-swap

v0.0.1

Published

A express middleware for swapping static files.

Downloads

6

Readme

nether swap

一个 express 中间件,劫持静态文件的请求,如文件系统中该存在符合规则的模拟文件,返回模拟文件。

用法

后台

var express = require('express');
var swap = require('nether-swap');

var app = express();
app.use(swap());
app.use('/static', express.static('static-dir'))

系统文件

  • /static/doudou-sdk.js (原始文件)
  • /static/doudou-sdk.mock.js (模拟文件)

前端请求

<!-- 响应 /static/doudou-sdk.mock.js -->
<script src='/static/doudou-sdk.js'></script>
<script src='/static/doudou-sdk.js?version=0.0.1'></script>

<!-- 配置了 noswap 响应 /static/doudou-sdk.js -->
<script src='/static/doudou-sdk.js?noswap'></script>

<!-- 不存在 other-lib.mock.js 响应 /static/other-lib.js -->
<script src='/static/other-lib.js'></script>

API: swap(optsions)

options.redirect (Boolean)

可选参数。

是否通过通过重定向的响应模拟问句。 默认为 false

options.rule (Function)

可选参数。

匹配代理的规则。默认方法如下:

/**
 * 将所有 *.js请求,响应为 *.mock.js
 * @parem reqpath 请求路径
 */
function (reqpath) {
  return reqpath.replace(/\.js($|\?.*)/, ".mock.js$1");
}

option.root (String)

可选参数。

表示静态目录根目录。默认为 .

完整配置实例

// dependencies omitted
app.use(swap({
  redirect: true,
  rule: function () {
    return reqpath.replace(/\.js($|\?.*)/, ".fake.js$1");
  },
  root: path.resolve(__dirname, './static-dir')
}))

开发/测试

# get the code
git clone <URL>
# install dependencies
npm i
# start test server
node test-server.js
# unit test
npm run test

名字

Nether Swap,移形换位,是 Dota/Dota 2 英雄——复仇之魂 (Vengeful Spirit) 的终极技能