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 🙏

© 2026 – Pkg Stats / Ryan Hefner

jquery-xhrfilter

v0.9.2

Published

A jQuery plugin to manipulate Ajax response before they get to the original requester.

Downloads

20

Readme

XHR Filters

XHR Filter is a utility library that replaces the original $.ajax with itself to allow manipulations on the response before the original requester gets the response.

This allows to implement things like password confirmations without needing to modify the original code in any way.

Example usage

$.ajaxRegisterFilter({
   fail: function (jqXHR, error, options, resolve, next) {
	   // Only handle 403's
	   if (jqXHR.status != "403") {
		   next();
		   return;
	   }

	   // Only handle "no_auth_token" errors
	   var content = JSON.parse(jqXHR.responseText);
	   if (!content.error || content.error != 'no_auth_token') {
		   next();
		   return;
	   }

	   modalValidate().then(function () {
		   // Clone the options, do not mutate the original object
		   options = $.extend({}, options, {headers: {'Auth-token': 'It\'s better with an auth token'}});

		   $.ajax(options).then(function (data, textStatus, innerXHR) {
			   resolve(data, innerXHR);
		   }, function () {
			   // Carry on if the request still failed ...
			   next();
		   });

	   }).fail(function () {
		   // If the validation is incorrect, go back to the normal cycle of things
		   next();
	   });
   }
});

The API

$.ajaxRegisterFilter(AjaxFilter filter)

There is the method to register a new filter

AjaxFilter

This can be implemented as a class or as a plain object. All methods are optional, but obviously it is recommended to put at least one ;-)

function before(AjaxOptions settings) {}

Executed before the request is sent, you may add headers or change the options any way you want

function done(jqXHR jqXHR, Object data, AjaxOptions settings, Function reject, Function next) {}

Executed when the request was successful, you can implement any logic here, even asynchronous.

You can call reject(String reason) if you decide the request should not pass.

function fail(jqXHR jqXHR, String thrownError, AjaxOptions settings, Function resolve, Function next) {}

Executed when the request was successful, you can implement any logic here, even asynchronous.

You can call resolve(Object data, jqXHR jqXHR) if you decide the request should pass.

Important for done and fail

You must call next() when you're done with your logic or else the code will not know when to execute the rest of the chain of filters.

The only time you can omit to call it is when you call resolve inside fail or reject inside done