Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xhr-shaper

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xhr-shaper - npm Package Compare versions

Comparing version 0.0.0 to 0.1.0

47

index.js

@@ -6,8 +6,38 @@ 'use strict';

var XHRShaper = function() {
this.maxBandwidth = Math.Infinity;
this.minLatency = 0;
this.minProgressEvents = 0;
this.randomness = 0;
var _maxBandwidth = Infinity;
var _minLatency = 0;
var _minProgressEvents = 0;
var _randomness = 0;
Object.defineProperty(this, "maxBandwidth", {
get: function() {
return Math.min(_maxBandwidth, XHRShaper.maxBandwidth);
},
set: function(val) { _maxBandwidth = val }
});
Object.defineProperty(this, "minLatency", {
get: function() {
return Math.max(_minLatency, XHRShaper.minLatency);
},
set: function(val) { _minLatency = val }
});
Object.defineProperty(this, "minProgressEvents", {
get: function() {
return Math.max(_minProgressEvents, XHRShaper.minProgressEvents);
},
set: function(val) { _minProgressEvents = val }
});
Object.defineProperty(this, "randomness", {
get: function() {
return Math.max(_randomness, XHRShaper.randomness);
},
set: function(val) { _randomness = val }
});
};
XHRShaper.maxBandwidth = Infinity;
XHRShaper.minLatency = 0;
XHRShaper.minProgressEvents = 0;
XHRShaper.randomness = 0;
var WindowXHR = window.XMLHttpRequest;

@@ -178,6 +208,11 @@

window.XMLHttpRequest = XMLHttpRequest;
XMLHttpRequest.Shaper = XHRShaper;
// Export our XMLHttpRequest mirror constructor as module
if (typeof module !== 'undefined') {
module.exports = Shaper;
module.exports = XMLHttpRequest;
}
// Overload native window constructor
window.XMLHttpRequest = XMLHttpRequest;

2

package.json
{
"name": "xhr-shaper",
"version": "0.0.0",
"version": "0.1.0",
"description": "Shapes your XHR requests to a max emulated bandwidth and latency, randomizes frequency of progress events",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -14,3 +14,3 @@ # xhr-shaper

NOTE: Loading this module will overload the XHR constructor in the `window` to produce a mirror object which will have the exact same behavior, but it's not an instance of the native `XMLHttpRequest` (in case that matters for some reason to you). The mirror XHR has an additional property called `shaper` ...
NOTE: Loading this module will overload the XHR constructor in the `window` to produce a mirror object which will have the exact same behavior, but it's not an instance of the native `XMLHttpRequest` (in case that matters for some reason to you). The mirror XHR has an additional property called `shaper` ...

@@ -40,2 +40,10 @@ ```

Or make these things global so they will apply on ALL requests!!!
```
// all requests will be limited to 64kbps and take at least 5000 ms
XMLHttpRequest.Shaper.maxBandwidth = 64;
XMLHttpRequest.Shaper.minLatency = 5000;
```
... wait for things to happen.

@@ -42,0 +50,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc