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

xhr-shaper

v2.3.2

Published

Shapes your XHR requests to a max emulated bandwidth and latency, randomizes frequency of progress events

Downloads

25

Readme

xhr-shaper

https://tchakabam.github.io/xhr-shaper/

Shapes your XHR requests to a max emulated bandwidth and latency, randomizes frequency of progress events

Screenshot of demo

Blog post: http://dispar.at/blog/2017/06/09/xhr-shaper/

Install:

npm install xhr-shaper

How to use:

As global/window shim

require('xhr-shaper').useGlobal();

// now XMLHttpRequest object is the shim

NOTE: Running useGlobal 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 ...

Or in a modular way

var XHRShaper = require('xhr-shaper');

var xhr = new XHRShaper.XMLHttpRequest(); 

NOTE: XHRShaper module exposes some fancy undocumented stuff like BaseXHR and objectMirrors. These might be moved into their own package in the future.

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(e) {
  console.log('readyState: ' + xhr.readyState);
};
xhr.onprogress = function(e) {
  console.log('Progress: ' + e.loaded + ' of ' + e.total);
};
xhr.withCredentials = false;
xhr.open('GET', "http://www.streambox.fr/playlists/test_001/stream_110k_48k_416x234_000.ts", true);
xhr.responseType = 'arraybuffer';

Create a bare XHR just as always ...

// Set your minimum desired latency !
xhr.shaper.minLatency = 1000;

// Set your maximum desired bandwidth
xhr.shaper.maxBandwidth = 512;

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.

xhr.send();

Test/dev:

Run npm run dev

Now go to http://localhost:8080/webpack-dev-server/

Automated BDD testsuite using Mocha.js

go to http://localhost:8080/webpack-dev-server/tests.html

TODOs:

  • randomizing feature
  • proper automated tests
  • implement all handlers as in https://xhr.spec.whatwg.org/

interface XMLHttpRequestEventTarget : EventTarget { // event handlers attribute EventHandler onloadstart; attribute EventHandler onprogress; attribute EventHandler onabort; attribute EventHandler onerror; attribute EventHandler onload; attribute EventHandler ontimeout; attribute EventHandler onloadend; };