http-info
v1.2.3
Published
HTTP Status Codes Utility
Downloads
3
Readme
HTTP Info
HTTP Status Codes Utility
A set of utility that allow to match, convert and list HTTP status codes.
Complete list of HTTP Status Codes can be found here.
Installation
$ npm install http-info
Usage
import httpInfo from 'http-info'
// Convert
httpInfo.convert(100) // => Continue
// Match
httpInfo.match.redirection(300) // => true
// List
httpInfo.list.serverError // => [500, 501, 502, 504, 505, 506, 507, 508, 510, 511]
API
convert(code)
Convert any HTTP code to its status message.
Code
type number
Return
string
| null
Example
httpInfo.convert(100) // => Continue
httpInfo.convert(301) // => Moved Permanently
// False value will return null
httpInfo.convert(600) // => null
match[<group>](code)
Returns whether an HTTP code exists in the specified group.
Group
informational
, success
, redirection
, clientError
, serverError
, _any
Code
type number
Return
boolean
Example
httpInfo.match.clientError(404) // => true
httpInfo.match.success(500) // => false
// To check for all groups, use `_any`
httpInfo.match._any(100) // => true
list[<group>]
Group
informational
, success
, redirection
, clientError
, serverError
Return
array
Example
httpInfo.list.success // => [200, 201, 202, ...]
httpInfo.list.serverError // ==> [500, 501, 502, ...]