twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

README.md (3458B)


      1 # Statuses
      2 
      3 [![NPM Version][npm-image]][npm-url]
      4 [![NPM Downloads][downloads-image]][downloads-url]
      5 [![Node.js Version][node-version-image]][node-version-url]
      6 [![Build Status][travis-image]][travis-url]
      7 [![Test Coverage][coveralls-image]][coveralls-url]
      8 
      9 HTTP status utility for node.
     10 
     11 This module provides a list of status codes and messages sourced from
     12 a few different projects:
     13 
     14   * The [IANA Status Code Registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml)
     15   * The [Node.js project](https://nodejs.org/)
     16   * The [NGINX project](https://www.nginx.com/)
     17   * The [Apache HTTP Server project](https://httpd.apache.org/)
     18 
     19 ## Installation
     20 
     21 This is a [Node.js](https://nodejs.org/en/) module available through the
     22 [npm registry](https://www.npmjs.com/). Installation is done using the
     23 [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
     24 
     25 ```sh
     26 $ npm install statuses
     27 ```
     28 
     29 ## API
     30 
     31 <!-- eslint-disable no-unused-vars -->
     32 
     33 ```js
     34 var status = require('statuses')
     35 ```
     36 
     37 ### var code = status(Integer || String)
     38 
     39 If `Integer` or `String` is a valid HTTP code or status message, then the
     40 appropriate `code` will be returned. Otherwise, an error will be thrown.
     41 
     42 <!-- eslint-disable no-undef -->
     43 
     44 ```js
     45 status(403) // => 403
     46 status('403') // => 403
     47 status('forbidden') // => 403
     48 status('Forbidden') // => 403
     49 status(306) // throws, as it's not supported by node.js
     50 ```
     51 
     52 ### status.STATUS_CODES
     53 
     54 Returns an object which maps status codes to status messages, in
     55 the same format as the
     56 [Node.js http module](https://nodejs.org/dist/latest/docs/api/http.html#http_http_status_codes).
     57 
     58 ### status.codes
     59 
     60 Returns an array of all the status codes as `Integer`s.
     61 
     62 ### var msg = status[code]
     63 
     64 Map of `code` to `status message`. `undefined` for invalid `code`s.
     65 
     66 <!-- eslint-disable no-undef, no-unused-expressions -->
     67 
     68 ```js
     69 status[404] // => 'Not Found'
     70 ```
     71 
     72 ### var code = status[msg]
     73 
     74 Map of `status message` to `code`. `msg` can either be title-cased or
     75 lower-cased. `undefined` for invalid `status message`s.
     76 
     77 <!-- eslint-disable no-undef, no-unused-expressions -->
     78 
     79 ```js
     80 status['not found'] // => 404
     81 status['Not Found'] // => 404
     82 ```
     83 
     84 ### status.redirect[code]
     85 
     86 Returns `true` if a status code is a valid redirect status.
     87 
     88 <!-- eslint-disable no-undef, no-unused-expressions -->
     89 
     90 ```js
     91 status.redirect[200] // => undefined
     92 status.redirect[301] // => true
     93 ```
     94 
     95 ### status.empty[code]
     96 
     97 Returns `true` if a status code expects an empty body.
     98 
     99 <!-- eslint-disable no-undef, no-unused-expressions -->
    100 
    101 ```js
    102 status.empty[200] // => undefined
    103 status.empty[204] // => true
    104 status.empty[304] // => true
    105 ```
    106 
    107 ### status.retry[code]
    108 
    109 Returns `true` if you should retry the rest.
    110 
    111 <!-- eslint-disable no-undef, no-unused-expressions -->
    112 
    113 ```js
    114 status.retry[501] // => undefined
    115 status.retry[503] // => true
    116 ```
    117 
    118 [npm-image]: https://img.shields.io/npm/v/statuses.svg
    119 [npm-url]: https://npmjs.org/package/statuses
    120 [node-version-image]: https://img.shields.io/node/v/statuses.svg
    121 [node-version-url]: https://nodejs.org/en/download
    122 [travis-image]: https://img.shields.io/travis/jshttp/statuses.svg
    123 [travis-url]: https://travis-ci.org/jshttp/statuses
    124 [coveralls-image]: https://img.shields.io/coveralls/jshttp/statuses.svg
    125 [coveralls-url]: https://coveralls.io/r/jshttp/statuses?branch=master
    126 [downloads-image]: https://img.shields.io/npm/dm/statuses.svg
    127 [downloads-url]: https://npmjs.org/package/statuses