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

Package detail

http-info

VeronQ10MIT1.2.3TypeScript support: included

HTTP Status Codes Utility

http, status, response

readme

HTTP Info

HTTP Status Codes Utility

Build Status npm version JavaScript Style Guide MIT license

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, ...]

License

MIT