/ node_modules / statuses / README.md
README.md
  1  # statuses
  2  
  3  [![NPM Version][npm-version-image]][npm-url]
  4  [![NPM Downloads][npm-downloads-image]][npm-url]
  5  [![Node.js Version][node-version-image]][node-version-url]
  6  [![Build Status][ci-image]][ci-url]
  7  [![Test Coverage][coveralls-image]][coveralls-url]
  8  [![OpenSSF Scorecard Badge][ossf-scorecard-badge]][ossf-scorecard-visualizer]
  9  
 10  HTTP status utility for node.
 11  
 12  This module provides a list of status codes and messages sourced from
 13  a few different projects:
 14  
 15    * The [IANA Status Code Registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml)
 16    * The [Node.js project](https://nodejs.org/)
 17    * The [NGINX project](https://www.nginx.com/)
 18    * The [Apache HTTP Server project](https://httpd.apache.org/)
 19  
 20  ## Installation
 21  
 22  This is a [Node.js](https://nodejs.org/en/) module available through the
 23  [npm registry](https://www.npmjs.com/). Installation is done using the
 24  [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
 25  
 26  ```sh
 27  $ npm install statuses
 28  ```
 29  
 30  ## API
 31  
 32  <!-- eslint-disable no-unused-vars -->
 33  
 34  ```js
 35  var status = require('statuses')
 36  ```
 37  
 38  ### status(code)
 39  
 40  Returns the status message string for a known HTTP status code. The code
 41  may be a number or a string. An error is thrown for an unknown status code.
 42  
 43  <!-- eslint-disable no-undef -->
 44  
 45  ```js
 46  status(403) // => 'Forbidden'
 47  status('403') // => 'Forbidden'
 48  status(306) // throws
 49  ```
 50  
 51  ### status(msg)
 52  
 53  Returns the numeric status code for a known HTTP status message. The message
 54  is case-insensitive. An error is thrown for an unknown status message.
 55  
 56  <!-- eslint-disable no-undef -->
 57  
 58  ```js
 59  status('forbidden') // => 403
 60  status('Forbidden') // => 403
 61  status('foo') // throws
 62  ```
 63  
 64  ### status.codes
 65  
 66  Returns an array of all the status codes as `Integer`s.
 67  
 68  ### status.code[msg]
 69  
 70  Returns the numeric status code for a known status message (in lower-case),
 71  otherwise `undefined`.
 72  
 73  <!-- eslint-disable no-undef, no-unused-expressions -->
 74  
 75  ```js
 76  status['not found'] // => 404
 77  ```
 78  
 79  ### status.empty[code]
 80  
 81  Returns `true` if a status code expects an empty body.
 82  
 83  <!-- eslint-disable no-undef, no-unused-expressions -->
 84  
 85  ```js
 86  status.empty[200] // => undefined
 87  status.empty[204] // => true
 88  status.empty[304] // => true
 89  ```
 90  
 91  ### status.message[code]
 92  
 93  Returns the string message for a known numeric status code, otherwise
 94  `undefined`. This object is the same format as the
 95  [Node.js http module `http.STATUS_CODES`](https://nodejs.org/dist/latest/docs/api/http.html#http_http_status_codes).
 96  
 97  <!-- eslint-disable no-undef, no-unused-expressions -->
 98  
 99  ```js
100  status.message[404] // => 'Not Found'
101  ```
102  
103  ### status.redirect[code]
104  
105  Returns `true` if a status code is a valid redirect status.
106  
107  <!-- eslint-disable no-undef, no-unused-expressions -->
108  
109  ```js
110  status.redirect[200] // => undefined
111  status.redirect[301] // => true
112  ```
113  
114  ### status.retry[code]
115  
116  Returns `true` if you should retry the rest.
117  
118  <!-- eslint-disable no-undef, no-unused-expressions -->
119  
120  ```js
121  status.retry[501] // => undefined
122  status.retry[503] // => true
123  ```
124  
125  ## License
126  
127  [MIT](LICENSE)
128  
129  [ci-image]: https://badgen.net/github/checks/jshttp/statuses/master?label=ci
130  [ci-url]: https://github.com/jshttp/statuses/actions?query=workflow%3Aci
131  [coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/statuses/master
132  [coveralls-url]: https://coveralls.io/r/jshttp/statuses?branch=master
133  [node-version-image]: https://badgen.net/npm/node/statuses
134  [node-version-url]: https://nodejs.org/en/download
135  [npm-downloads-image]: https://badgen.net/npm/dm/statuses
136  [npm-url]: https://npmjs.org/package/statuses
137  [npm-version-image]: https://badgen.net/npm/v/statuses
138  [ossf-scorecard-badge]: https://api.securityscorecards.dev/projects/github.com/jshttp/statuses/badge
139  [ossf-scorecard-visualizer]: https://kooltheba.github.io/openssf-scorecard-api-visualizer/#/projects/github.com/jshttp/statuses