The `http-status-response-codes` package (current version 1.0.2) provides a JavaScript utility for handling HTTP status codes, drawing inspiration from Java's Spring Boot framework. It exports an `HttpStatus` class that can be instantiated with a numeric status code (as a string) or a response-like object containing a `status` property. Instances of `HttpStatus` offer methods to categorize the status code (e.g., `is2xxSuccessful()`, `is4xxClientError()`, `isError()`, `is1xxInformational()`, `is3xxRedirection()`, `is5xxServerError()`), and retrieve its name, code value, and description. Additionally, the package exports a `statusCodes` object, providing a convenient enum-like collection of standard HTTP status codes. This library facilitates programmatic handling and classification of HTTP responses in a structured manner. Given its version and CommonJS-centric examples, the package appears to be stable and feature-complete, but not actively undergoing modern JavaScript evolution.
npm install http-status-response-codesVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate `HttpStatus` with both a string and a mock response object, how to use its categorization methods (`is4xxClientError`, `is2xxSuccessful`, `isError`), and how to access specific status code values from the `statusCodes` object. It highlights common usage patterns for checking HTTP response types.
Use `const HttpStatus = require('http-status-response-codes');` and `const { statusCodes } = require('http-status-response-codes');` for all imports.Ensure the object passed to `new HttpStatus()` has a `status` property containing the numeric HTTP status code, e.g., `new HttpStatus({ status: response.status })`.Evaluate against more actively maintained alternatives if up-to-date features, comprehensive type support, or continuous maintenance are critical for your project.
Ensure the argument passed to `new HttpStatus()` is either a valid numeric string (e.g., `'200'`) or an object with a `status` property (e.g., `{ status: 200 }`).The `HttpStatus` class is the default export. Use `const HttpStatus = require('http-status-response-codes');` to import it correctly.For CommonJS, use `const { statusCodes } = require('http-status-response-codes');` to correctly destructure the named export.No dependency data recorded yet.