Skip to content

shahradelahi/status-codes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

@se-oss/status-codes

CI NPM Version MIT License Install Size

@se-oss/status-codes offers strongly typed utilities to safely convert between HTTP status phrases and their numeric codes. Enjoy full TypeScript type safety and compile-time checks in your projects.


๐Ÿ“ฆ Installation

npm i @se-oss/status-codes

๐Ÿ“– Usage

import { getStatusCode, getStatusPhrase, StatusCodes, StatusPhrases } from '@se-oss/status-codes';

getStatusPhrase(200); // returns 'Ok'
getStatusPhrase(StatusCodes.CREATED); // returns 'Created'
getStatusPhrase(418); // returns "I'm a teapot"

getStatusCode('OK'); // returns 200
getStatusCode('CREATED'); // returns 201

console.log(StatusCodes.FORBIDDEN); // prints 403
console.log(StatusPhrases.IM_A_TEAPOT); // prints "I'm a teapot"

๐Ÿ“š Documentation

For all configuration options, please see the API docs.

API
/**
 * Returns the HTTP status code for a given status phrase.
 *
 * @param phrase - The HTTP status phrase
 * @returns The corresponding HTTP status code
 * @throws {TypeError} If input is not valid or phrase is unknown
 */
declare function getStatusCode<T, U>(phrase: T): U;

/**
 * Returns the HTTP status phrase for a given status code.
 *
 * @param code - The HTTP status code
 * @returns The corresponding HTTP status phrase
 * @throws {TypeError} If input is not valid or code is unknown
 */
declare function getStatusPhrase<T, C, U>(code: T): U;

๐Ÿค Contributing

Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub.

Thanks again for your support, it is much appreciated! ๐Ÿ™

๐Ÿ“‘ References

License

MIT ยฉ Shahrad Elahi and contributors.

About

๐ŸŒType-safe HTTP Status utilities.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors