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

resbrev

v1.0.0

Published

A chainable response helper that implements most well known status codes and some mime types

Downloads

5

Readme

resbrev

Response Brevity

This is a small utlity library for assisting in setting up response object in Connect 3.x. It is based on Quip and contains the same chainable API.

install

npm install --save resbrev

use

  • Wrap a single response object

var http = require('http'), resbrev = require('resbrev'); http.createServer(function (req, res) { resbrev(res); res.ok('Hello World\n') }).listen(1337, '127.0.0.1'); console.log('Server running at http://127.0.0.1:1337/');

  • Connect / Express middleware var conenct = require('connect'), resbrev = require('resbrev'); var app = connect(resbrev) .use('/api', function(req,res,next){ res.json({foo: 'bar'}); });

methods

Response objects will be extended with the following non-enumerable, non-writable methods. For the success, redirect, client error, server error, mime tpye, and fun methods, sending data will end the request. Data is almost always optional (jsonp being the exception).

helpers

  • s(statusCode) - set the status code of the response
  • h(headers) - set headers on the response, as an object containing key-value pairs of headers and values ({'Content-Type': 'application/json', 'x-hello': 'Hi there'})
  • t(mimeType) - specifically set the 'Content-Type' header to the value of "mimeType"

success

  • ok(data) - sends status code 200 and data if present
  • created(data) - sends 201
  • accepted(data) - sends 202

redirects

  • moved(location) - sends 301 (moved permanently) and sets "location" header to "location" (required)
  • redirect(location) - sends 302, use like "moved()"
  • found(location) - identical to "redirect()"
  • notModified() - sends 304

client errors

  • badRequest(data) - sends 400
  • unauthorized(data) - sends 401
  • payMe(data) - sends 402
  • forbidden(data) - sends 403
  • notFound(data) - sends 404
  • notAllowed(data) - sends 405
  • notAcceptable(data) - sends 406
  • proxyAuthRequired(data) - sends 407
  • requestTimeout(data) - sends 408
  • conflict(data) - sends 409
  • gone(data) - sends 410
  • lengthRequired(data) - sends 411
  • preconditionFailed(data) - sends 412
  • requestEntityTooLarge(data) - sends 413
  • requestUriTooLong(data) - sends 414
  • unsupportedMediaType(data) - sends 415
  • requestRangeNotSatisfiable(data) - sends 416
  • expectationFailed(data) - sends 417

server errors

  • error(data) - sends 500
  • notImplemented(data) - sends 501
  • badGateway(data) - sends 502
  • serviceUnavailable(data) - sends 503
  • gatewayTimeout(data) - sends 504
  • httpVersionNotSupported(data) - sends 505

mime types

  • text(data) - sets content-type to "text/plain"
  • plain(data) - sets content-type to "text/plain"
  • html(data) - sets content-type to "text/html"
  • xhtml(data) - sets content-type to "application/xhtml+xml"
  • css(data) - sets content-type to "text/css"
  • xml(data) - sets content-type to "text/xml"
  • atom(data) - sets content-type to "tapplication/atom+xml"
  • rss(data) - sets content-type to "application/rss+xml"
  • js(data) - sets content-type to "application/javascript"
  • json(data) - sets content-type to "application/json"
  • jsonp(callback, data) - sets content-type to "application/json" and adjusts response body for jsonp, "callback = (data);"

for fun

  • iAmATeapot(data) - sends 418
  • enhanceYourCalm(data) - sends 420