This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@tshttp/status
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

@tshttp/status 🎰

Ultra typed, over documented, and neatly organised HTTP status enums, to use for a great developper experience.

Get started

yarn add @tshttp/status
npm install @tshttp/status
import { Status } from '@tshttp/status'

res.sendStatus(Status.Created)

Enums

Status enum is composed of the following exported enums:

  • InformationStatus for 1xx responses.
  • SuccessStatus for 2xx responses.
  • RedirectionStatus for 3xx responses.
  • ErrorStatus for 4xx and 5xx responses.
import { ErrorStatus } from '@tshttp/status'
import { HttpError } from '@tshttp/error'

throw HttpError(ErrorStatus.Forbidden)

These enums are actually object litterals with a const assertion.`

Unions

When use as a type, each category is a union of corresponding status codes.

import { RedirectionStatus } from '@tshttp/status'

function redirect(status: RedirectionStatus, url: string) {
  // ...
}

Reason phrase

A simple method called reason transforms a status code into its human readable reason phrase :

import { reason, ErrorStatus } from '@tshttp/status'

reason(200) // "OK"
reason(301) // "Moved Permanently"
reason(404) // "Not Found"
reason(ErrorStatus.ImATeapot) // "I'm a teapot"

Package Sidebar

Install

npm i @tshttp/status

Weekly Downloads

1,038

Version

2.0.0

License

MIT

Unpacked Size

63.9 kB

Total Files

8

Last publish

Collaborators

  • jeben