Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

statuses

jshttp185.8mMIT2.0.1TypeScript support: definitely-typed

HTTP status utility

http, status, code

readme

statuses

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

HTTP status utility for node.

This module provides a list of status codes and messages sourced from a few different projects:

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install statuses

API

var status = require('statuses')

status(code)

Returns the status message string for a known HTTP status code. The code may be a number or a string. An error is thrown for an unknown status code.

status(403) // => 'Forbidden'
status('403') // => 'Forbidden'
status(306) // throws

status(msg)

Returns the numeric status code for a known HTTP status message. The message is case-insensitive. An error is thrown for an unknown status message.

status('forbidden') // => 403
status('Forbidden') // => 403
status('foo') // throws

status.codes

Returns an array of all the status codes as Integers.

status.code[msg]

Returns the numeric status code for a known status message (in lower-case), otherwise undefined.

status['not found'] // => 404

status.empty[code]

Returns true if a status code expects an empty body.

status.empty[200] // => undefined
status.empty[204] // => true
status.empty[304] // => true

status.message[code]

Returns the string message for a known numeric status code, otherwise undefined. This object is the same format as the Node.js http module http.STATUS_CODES.

status.message[404] // => 'Not Found'

status.redirect[code]

Returns true if a status code is a valid redirect status.

status.redirect[200] // => undefined
status.redirect[301] // => true

status.retry[code]

Returns true if you should retry the rest.

status.retry[501] // => undefined
status.retry[503] // => true

License

MIT

changelog

2.0.1 / 2021-01-03

  • Fix returning values from Object.prototype

2.0.0 / 2020-04-19

  • Drop support for Node.js 0.6
  • Fix messaging casing of 418 I'm a Teapot
  • Remove code 306
  • Remove status[code] exports; use status.message[code]
  • Remove status[msg] exports; use status.code[msg]
  • Rename 425 Unordered Collection to standard 425 Too Early
  • Rename STATUS_CODES export to message
  • Return status message for statuses(code) when given code

1.5.0 / 2018-03-27

  • Add 103 Early Hints

1.4.0 / 2017-10-20

  • Add STATUS_CODES export

1.3.1 / 2016-11-11

  • Fix return type in JSDoc

1.3.0 / 2016-05-17

  • Add 421 Misdirected Request
  • perf: enable strict mode

1.2.1 / 2015-02-01

  • Fix message for status 451
    • 451 Unavailable For Legal Reasons

1.2.0 / 2014-09-28

  • Add 208 Already Repored
  • Add 226 IM Used
  • Add 306 (Unused)
  • Add 415 Unable For Legal Reasons
  • Add 508 Loop Detected

1.1.1 / 2014-09-24

  • Add missing 308 to codes.json

1.1.0 / 2014-09-21

  • Add codes.json for universal support

1.0.4 / 2014-08-20

  • Package cleanup

1.0.3 / 2014-06-08

  • Add 308 to .redirect category

1.0.2 / 2014-03-13

  • Add .retry category

1.0.1 / 2014-03-12

  • Initial release