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

hsc

v0.2.3

Published

Comprehensive HTTP Status Code Information in Node.js Made Easy!

Downloads

7

Readme

hsc

Build Status    npm version  npm version   
NPM

Comprehensive HTTP Status Code Information in Node.js Made Easy!

var hsc = require('hsc');

hsc.code(404, function(information) {
  console.log(information.summary);
});
requested resource could not be found

hsc is an npm package that aims to simplify the retrieval of HTTP status code information. hsc relies on the wonderful httpstatus.es API.

Practical uses of hsc include:

  • Translating HTTP status codes into something users can understand.

hsc is simple to install and even more simple to use.

Installation

hsc is an npm module, so simply run:

npm install hsc

or, if you want to add hsc as a dependency to your package.json file, run:

npm install hsc --save

Usage

Standard report with bare-bones information.

hsc.code(200, function(information) {
  console.log(information);
});
{
  "code": "200",
  "title": "OK",
  "summary": "standard response for successful HTTP requests",
  "status": "success"
}

Report with descriptions, but no references.

hsc.code(200, function(information) {
  console.log(information);
}, true);

hsc.code(200, function(information) {
  console.log(information);
}, true, false);
{
  "code": "200",
  "title": "OK",
  "summary": "standard response for successful HTTP requests",
  "descriptions": {
    "wikipedia": {
      "body": "Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request the response will contain an entity describing or containing the result of the action.",
      "link": "http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#200"
    },
    "ietf": {
      "body": "The request has succeeded. The information returned with the response is dependent on the method used in the request, for example: GET an entity corresponding to the requested resource is sent in the response; HEAD the entity-header fields corresponding to the requested resource are sent in the response without any message-body; POST an entity describing or containing the result of the action;",
      "link": "http://www.ietf.org/rfc/rfc2616.txt"
    }
  },
  "status": "success"
}

Report with references, but no descriptions.

hsc.code(200, function(information) {
  console.log(information);
}, false, true);
{
  "code": "200",
  "title": "OK",
  "summary": "standard response for successful HTTP requests",
  "references": {
    "rails": {
      "title": "Rails HTTP Status Symbol",
      "value": ":ok"
    }
  },
  "status": "success"
}

Report with both descriptions and references.

hsc.code(200, function(information) {
  console.log(information);
}, true, true);
{
  "code": "200",
  "title": "OK",
  "summary": "standard response for successful HTTP requests",
  "descriptions": {
    "wikipedia": {
      "body": "Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request the response will contain an entity describing or containing the result of the action.",
      "link": "http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#200"
    },
    "ietf": {
      "body": "The request has succeeded. The information returned with the response is dependent on the method used in the request, for example: GET an entity corresponding to the requested resource is sent in the response; HEAD the entity-header fields corresponding to the requested resource are sent in the response without any message-body; POST an entity describing or containing the result of the action;",
      "link": "http://www.ietf.org/rfc/rfc2616.txt"
    }
  },
  "references": {
    "rails": {
      "title": "Rails HTTP Status Symbol",
      "value": ":ok"
    }
  },
  "status": "success"
}

In the event of an error, the status property will become "error" and the error property will hold the error.

Invalid HTTP status code.

hsc.code(2500, function(information) {
  console.log(information);
});
{
  "status": "error",
  "error": "Invalid code 2500."
}

Miscellaneous error during request.

// Some call.
{
  "status": "error",
  "error": "Error with request."
}

These examples, excluding the "Miscellaneous error during request.", can also be found in /examples/everything.js.

Contributing

Contributions are always welcome.

We follow Airbnb's coding standard, so make sure you use that as a guideline.

Fork our code, make a new branch, and send a pull request.

TODO: