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

gatesjs

v1.0.4

Published

Set specific callbacks for specific server responses

Downloads

29

Readme

Gates.js

Build Status

Set specific callbacks for specific responses.

Usage

Install gates.js module:

$ npm install gatesjs --save

Include module in your project:

const gates = require("gatesjs");

Set up your gates in main request callback. Using set method pass response's code value:

new gates().set(response.statusCode);

Each gate function needs two parameters: array with condition rules and callback function. The first array's element is an expected status code (required, in example below 200), the second one is an optional expression (e.g. foo === true):

request("http://example.com/foo.json", (error, response, body) => {

  body = JSON.parse(body); // => { foo: true }

  new gates().set(response.code)

       .gate([200 , body.foo === true], () => { console.log('Hello 200 status callback and true foo!'); });

});

If there's a possibility the condition could not be met, set default callback using default method:

 .default(() => { console.log('Hello default callback!'); });

For any kind of response codes or any expression use asterisk * argument:

 .gate([ "*", data.foo === false ], () => { console.log('Hello callback for whatever status and falsy foo!'); })
 .gate([ 404, "*" ], () => { console.log('Hello callback for 404 status and whatever!'); });

When you clone the repository check for more examples by launching $ node index.js after $ npm install.

License

MIT.