Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-status

Package Overview
Dependencies
Maintainers
0
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-status - npm Package Compare versions

Comparing version 1.8.0 to 1.8.1

CHANGELOG.md

85

package.json
{
"name": "http-status",
"version": "1.8.0",
"version": "1.8.1",
"description": "Interact with HTTP status code",

@@ -24,26 +24,29 @@ "homepage": "https://github.com/adaltas/node-http-status",

"devDependencies": {
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@eslint/core": "^0.6.0",
"@eslint/js": "^9.11.1",
"@types/eslint__js": "^8.42.3",
"@types/mocha": "^10.0.8",
"@types/node": "^22.7.4",
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@types/mocha": "^9.1.1",
"@types/node": "^18.7.15",
"@types/should": "^13.0.0",
"commitlint": "^19.5.0",
"eslint": "^9.11.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-prettier": "^5.2.1",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"mocha": "10.7.3",
"prettier": "^3.3.3",
"coffeescript": "2.7.0",
"commitlint": "^17.1.2",
"husky": "^8.0.1",
"mocha": "10.0.0",
"should": "13.2.3",
"standard-version": "^9.5.0",
"ts-node": "^10.9.2",
"tsup": "^8.3.0",
"typescript": "^5.6.2",
"typescript-eslint": "^8.8.0"
"ts-node": "^10.9.1",
"typescript": "^4.8.2"
},
"coffeelintConfig": {
"indentation": {
"level": "error",
"value": 2
},
"line_endings": {
"level": "error",
"value": "unix"
},
"max_line_length": {
"level": "ignore"
}
},
"contributors": [

@@ -59,26 +62,8 @@ {

],
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs"
},
"./*": {
"import": "./dist/*.js",
"types": "./dist/*.d.ts",
"require": "./dist/*.cjs"
}
},
"files": [
"dist"
],
"lint-staged": {
"*.js": "npm run lint:fix",
"*.md": "prettier -w"
},
"mocha": {
"throw-deprecation": false,
"loader": "ts-node/esm",
"throw-deprecation": true,
"require": [
"should"
"should",
"coffeescript/register.js",
"ts-node/register"
],

@@ -90,2 +75,4 @@ "inline-diffs": true,

},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"engines": {

@@ -95,7 +82,6 @@ "node": ">= 0.4.0"

"scripts": {
"build": "tsup-node",
"lint:check": "eslint",
"lint:fix": "eslint --fix",
"lint:staged": "npx lint-staged",
"build": "coffee -b -o lib src && cp src/index.d.ts lib",
"prepare": "husky install",
"pretest": "npm run build",
"prerelease": "npm run build && git update-index --refresh && git diff-index --quiet HEAD --",
"release": "standard-version",

@@ -106,5 +92,4 @@ "release:minor": "standard-version --release-as minor",

"postrelease": "git push --follow-tags origin master",
"test": "mocha \"test/**/*.{js,ts}\""
},
"type": "module"
"test": "mocha \"test/**/*.{coffee,ts}\""
}
}

@@ -0,1 +1,3 @@

[![Build Status](https://secure.travis-ci.org/adaltas/node-http-status.png)](http://travis-ci.org/adaltas/node-http-status)
# HTTP Status codes for Node.js

@@ -7,16 +9,10 @@

Once you import or require this module, you may call it with either an HTTP code or a status name. With an HTTP code, you will get the status name while with a status name you will get an HTTP code or some complementary information.
Once you require this module, you may call it with either an HTTP code or a message name. With an HTTP code, you will get the message name while with a message name you will get an HTTP code.
For example, `status[418]` return `IM_A_TEAPOT` while `status.IM_A_TEAPOT` return `"I'm a teapot"` and `status.IM_A_TEAPOT_CODE` returns `418`.
### HTTP Status codes
The package is written in TypeScript and built for CommonJS and ESM.
HTTP code names, messages, and classes are respectively accessible with the property `{code}_NAME`, `{code}_MESSAGE` and `{code}_CLASS`. This includes all statuses in the [IANA HTTP Status Code Registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml), with the only addition being `418 I'm a teapot`.
## HTTP Status codes
Extra status code are also made available that are not defined in the IANA registry, but used by popular software. They are grouped by category. Specific properties are exported by `http-status` under the property `extra` followed by the category name. Also, extra codes are merge with regular status codes and made available as modules available inside `http-status/lib/{category}`.
HTTP code names, information, and classes are respectively accessible with the property `{code}_NAME`, `{code}_MESSAGE` and `{code}_CLASS`. This includes all statuses in the [IANA HTTP Status Code Registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml), with the only addition being `418 I'm a teapot`.
## Extra codes
Extra status code are also made available that are not defined in the IANA registry, but used by popular softwares. They are grouped by category. Specific properties are exported by `http-status` under the property `extra` followed by the category name. Also, extra codes are merge with regular status codes and made available as modules available inside `http-status/lib/{category}`.
Available categories are:

@@ -35,10 +31,8 @@

They are accessible throught the `status.extra[category]` property. It is also possible to import one of the category with `import status from "http-status/<category>" or `const status = require("http-status/<category>")`. In the later case, all the categories properties are merge with the common HTTP statuses.
### HTTP Status code classes
## HTTP Status code classes
In addition to HTTP status codes, this module also contains status code classes under the `classes` property. Similar to HTTP codes, you can access class names and messages with the property `{class}_NAME` and `{class}_MESSAGE`
In addition to HTTP status codes, this module also contains status code classes under the `classes` property. Similar to HTTP codes, you can access class names and messages with the property `{class}_NAME` and `{class}_MESSAGE`.
## API
## API organization
The API is structured as follows:

@@ -101,8 +95,6 @@

## Example API usage
### Example usage
The [api example](./samples/api.js) illustrate how to access status names by code and number and how to extra various associated informations.
```javascript
import status from "http-status";
const status = require('http-status');

@@ -116,11 +108,11 @@ console.info(status.INTERNAL_SERVER_ERROR);

console.info(status["500_NAME"]);
console.info(status['500_NAME']);
console.info(status[`${status.INTERNAL_SERVER_ERROR}_NAME`]);
// Both output: "INTERNAL_SERVER_ERROR"
console.info(status["500_MESSAGE"]);
console.info(status['500_MESSAGE']);
console.info(status[`${status.INTERNAL_SERVER_ERROR}_MESSAGE`]);
// Both output: "A generic error message, given when an unexpected condition was encountered and no more specific message is suitable."
console.info(status["500_CLASS"]);
console.info(status['500_CLASS']);
console.info(status[`${status.INTERNAL_SERVER_ERROR}_CLASS`]);

@@ -130,6 +122,6 @@ // Both output: "5xx"

## Example using `classes`
### Example using `classes`
```javascript
import status from "http-status";
const status = require('http-status');

@@ -161,28 +153,24 @@ const responseCode = status.INTERNAL_SERVER_ERROR;

## Example using the `extra` property
### Example using the `extra` property
```javascript
// Accessing property from the NGINX category
import status from "http-status";
console.info(status.extra.nginx.NO_RESPONSE);
const status = require('http-status');
console.info(status.extra.nginx.NO_RESPONSE)
// Accessing default HTTP status merged with NGINX status
import status from "http-status/lib/nginx";
const status = require('http-status/lib/nginx');
console.info(status.IM_A_TEAPOT);
console.info(status.NO_RESPONSE);
console.info(status.NO_RESPONSE)
```
## Example integrating Express
### Example integrating Express
The [express example](./samples/express.js) integrate the library with a real wold usage.
```javascript
import express from "express";
import redis from "redis";
import status from "http-status";
const express = require('express'),
redis = require('redis'),
status = require('http-status');
// New Express HTTP server
const app = express.createServer();
// Regster a route
app.get("/", (req, res) => {
app.get('/', (req, res) => {
const client = redis.createClient();

@@ -208,3 +196,3 @@ client.ping((err, msg) => {

The project is sponsored by [Adaltas](https://www.adaltas.com) based in Paris, France. Adaltas offers support and consulting on distributed systems, big data and open source.
This package is developed by [Adaltas](https://www.adaltas.com).

@@ -211,0 +199,0 @@ ## Developers

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc