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

http-status

Package Overview
Dependencies
Maintainers
1
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.7.4 to 1.8.0

dist/chunk-CUNVWAK5.js

85

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

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

"devDependencies": {
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@types/mocha": "^9.1.1",
"@types/node": "^18.7.15",
"@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",
"@types/should": "^13.0.0",
"coffeescript": "2.7.0",
"commitlint": "^17.1.2",
"husky": "^8.0.1",
"mocha": "10.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",
"should": "13.2.3",
"standard-version": "^9.5.0",
"ts-node": "^10.9.1",
"typescript": "^4.8.2"
"ts-node": "^10.9.2",
"tsup": "^8.3.0",
"typescript": "^5.6.2",
"typescript-eslint": "^8.8.0"
},
"coffeelintConfig": {
"indentation": {
"level": "error",
"value": 2
},
"line_endings": {
"level": "error",
"value": "unix"
},
"max_line_length": {
"level": "ignore"
}
},
"contributors": [

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

],
"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": true,
"throw-deprecation": false,
"loader": "ts-node/esm",
"require": [
"should",
"coffeescript/register.js",
"ts-node/register"
"should"
],

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

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

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

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

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

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

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

[![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

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

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.
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.
### HTTP Status codes
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 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`.
The package is written in TypeScript and built for CommonJS and ESM.
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 Status codes
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:

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

### HTTP Status code classes
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.
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`
## HTTP Status code classes
## API
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 organization
The API is structured as follows:

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

### Example usage
## Example API 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
const status = require('http-status');
import status from "http-status";

@@ -108,11 +116,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`]);

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

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

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

### Example using the `extra` property
## Example using the `extra` property
```javascript
// Accessing property from the NGINX category
const status = require('http-status');
console.info(status.extra.nginx.NO_RESPONSE)
import status from "http-status";
console.info(status.extra.nginx.NO_RESPONSE);
// Accessing default HTTP status merged with NGINX status
const status = require('http-status/lib/nginx');
import status from "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
const express = require('express'),
redis = require('redis'),
status = require('http-status');
import express from "express";
import redis from "redis";
import status from "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();

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

This package is developed by [Adaltas](https://www.adaltas.com).
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.

@@ -199,0 +211,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