https://github.com/shahradelahi/status-codes
🌐Type-safe HTTP Status utilities.
https://github.com/shahradelahi/status-codes
codes http javascript status
Last synced: 5 months ago
JSON representation
🌐Type-safe HTTP Status utilities.
- Host: GitHub
- URL: https://github.com/shahradelahi/status-codes
- Owner: shahradelahi
- License: mit
- Created: 2025-03-28T03:17:46.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-08-24T03:24:59.000Z (5 months ago)
- Last Synced: 2025-09-01T07:10:54.372Z (5 months ago)
- Topics: codes, http, javascript, status
- Language: TypeScript
- Homepage: https://npmjs.com/@se-oss/status-codes
- Size: 85.9 KB
- Stars: 15
- Watchers: 1
- Forks: 2
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @se-oss/status-codes
[](https://github.com/shahradelahi/status-codes/actions/workflows/ci.yml)
[](https://www.npmjs.com/package/@se-oss/status-codes)
[](/LICENSE)
[](https://packagephobia.com/result?p=@se-oss/status-codes)
**@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](#-installation)
- [Usage](#-usage)
- [Documentation](#-documentation)
- [Contributing](#-contributing)
- [References](#-references)
- [License](#license)
## 📦 Installation
```bash
npm i @se-oss/status-codes
```
## 📖 Usage
```typescript
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](https://www.jsdocs.io/package/@se-oss/status-codes).
##### API
```typescript
/**
* 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(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(code: T): U;
```
## 🤝 Contributing
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on [GitHub](https://github.com/shahradelahi/status-codes).
Thanks again for your support, it is much appreciated! 🙏
## 📑 References
- MDN Web Docs: [HTTP Status Codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status)
## License
[MIT](/LICENSE) © [Shahrad Elahi](https://github.com/shahradelahi) and [contributors](https://github.com/shahradelahi/status-codes/graphs/contributors).