{"id":19721115,"url":"https://github.com/paramsiddharth/statushttp","last_synced_at":"2025-07-11T00:05:11.818Z","repository":{"id":57370305,"uuid":"332809962","full_name":"paramsiddharth/statushttp","owner":"paramsiddharth","description":"A JavaScript library for working with HTTP status codes.","archived":false,"fork":false,"pushed_at":"2022-01-30T05:38:33.000Z","size":144,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-08T12:25:50.156Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paramsiddharth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-25T16:28:24.000Z","updated_at":"2024-06-30T10:34:28.000Z","dependencies_parsed_at":"2022-09-18T22:23:46.926Z","dependency_job_id":null,"html_url":"https://github.com/paramsiddharth/statushttp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/paramsiddharth/statushttp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paramsiddharth%2Fstatushttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paramsiddharth%2Fstatushttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paramsiddharth%2Fstatushttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paramsiddharth%2Fstatushttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paramsiddharth","download_url":"https://codeload.github.com/paramsiddharth/statushttp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paramsiddharth%2Fstatushttp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264696187,"owners_count":23650934,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T23:13:28.061Z","updated_at":"2025-07-11T00:05:11.797Z","avatar_url":"https://github.com/paramsiddharth.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HTTP Status Codes (`statushttp`)\r\nA JavaScript library for working with HTTP status codes.\r\n\r\nAll status codes are taken from the [IANA Status Code Registry](https://www.iana.org/assignments/http-status-codes).\r\n\r\nThe library works both in the front-end (VanillaJS) and the back-end (NodeJS), supporting a variety of imports. It can also be used as a command-line tool to work with HTTP status codes.\r\n\r\n## Installation\r\nInstall it via NPM.\r\n``` bash\r\n# Local\r\nnpm i statushttp\r\n\r\n# Global\r\nnpm i -g statushttp\r\n```\r\n\r\n## Quick Start\r\n``` js\r\nconst { sc } = require('statushttp');\r\n// Or import { sc } from 'statushttp'; for modules\r\n\r\n// Passing case-insensitive text with spaces\r\nconsole.log(sc('not found').Code); // 404\r\nconsole.log(sc(201).Desc); // \"Created\"\r\n\r\n// Identifier\r\nconsole.log(sc(405).Text); // \"METHOD_NOT_ALLOWED\"\r\n```\r\n\r\n## Importing\r\n- CommonJS\r\n  ``` js\r\n  const { statusCode, statusText, ... } = require('statushttp');\r\n  ```\r\n- ES6\r\n  ``` mjs\r\n  import { statusCode, statusText, ... } from 'statushttp';\r\n  ```\r\n- AMD (require.js)\r\n  ``` js\r\n  require(['main.js'], () =\u003e {\r\n    // Assuming path for 'statushttp' configured at 'node_modules/statushttp/statushttp' inside main.js\r\n  \trequire(['statushttp'], ({\r\n  \t\tstatusCode,\r\n  \t\tstatusText,\r\n  \t\t...\r\n  \t}) =\u003e {\r\n  \t\t...\r\n  \t});\r\n  });\r\n  ```\r\n- HTML + VanillaJS\r\n  ``` html\r\n  \u003c!-- Minified --\u003e\r\n  \u003cscript src='node_modules/statushttp/statushttp.min.js'\u003e\u003c/script\u003e\r\n\r\n  \u003c!-- Not minified --\u003e\r\n  \u003cscript src='node_modules/statushttp/statushttp.js'\u003e\u003c/script\u003e\r\n\r\n  \u003cscript\u003e\r\n\t\t// statusText, statusCode, et cetera, are accessible now.\r\n  \u003c/script\u003e\r\n  ```\r\n\r\n## List of Identifiers Used\r\nThe following identifiers are used in `statushttp` to identify\r\nvarious HTTP statuses.\r\n\r\n| Identifier                                | Code |\r\n| ------------------------------------------ | --- |\r\n| CONTINUE                                 | 100 |\r\n| SWITCHING_PROTOCOLS                      | 101 |\r\n| PROCESSING                               | 102 |\r\n| EARLY_HINTS                              | 103 |\r\n| OK                                       | 200 |\r\n| CREATED                                  | 201 |\r\n| ACCEPTED                                 | 202 |\r\n| NON_AUTHORITATIVE_INFORMATION            | 203 |\r\n| NO_CONTENT                               | 204 |\r\n| RESET_CONTENT                            | 205 |\r\n| PARTIAL_CONTENT                          | 206 |\r\n| MULTI_STATUS                             | 207 |\r\n| ALREADY_REPORTED                         | 208 |\r\n| IM_USED                                  | 226 |\r\n| MULTIPLE_CHOICES                         | 300 |\r\n| MOVED_PERMANENTLY                        | 301 |\r\n| FOUND                                    | 302 |\r\n| SEE_OTHER                                | 303 |\r\n| NOT_MODIFIED                             | 304 |\r\n| USE_PROXY                                | 305 |\r\n| UNUSED                                   | 306 |\r\n| TEMPORARY_REDIRECT                       | 307 |\r\n| PERMANENT_REDIRECT                       | 308 |\r\n| BAD_REQUEST                              | 400 |\r\n| UNAUTHORIZED                             | 401 |\r\n| PAYMENT_REQUIRED                         | 402 |\r\n| FORBIDDEN                                | 403 |\r\n| NOT_FOUND                                | 404 |\r\n| METHOD_NOT_ALLOWED                       | 405 |\r\n| NOT_ACCEPTABLE                           | 406 |\r\n| PROXY_AUTHENTICATION_REQUIRED            | 407 |\r\n| REQUEST_TIMEOUT                          | 408 |\r\n| CONFLICT                                 | 409 |\r\n| GONE                                     | 410 |\r\n| LENGTH_REQUIRED                          | 411 |\r\n| PRECONDITION_FAILED                      | 412 |\r\n| PAYLOAD_TOO_LARGE                        | 413 |\r\n| URI_TOO_LONG                             | 414 |\r\n| UNSUPPORTED_MEDIA_TYPE                   | 415 |\r\n| RANGE_NOT_SATISFIABLE                    | 416 |\r\n| EXPECTATION_FAILED                       | 417 |\r\n| MISDIRECTED_REQUEST                      | 421 |\r\n| UNPROCESSABLE_ENTITY                     | 422 |\r\n| LOCKED                                   | 423 |\r\n| FAILED_DEPENDENCY                        | 424 |\r\n| TOO_EARLY                                | 425 |\r\n| UPGRADE_REQUIRED                         | 426 |\r\n| PRECONDITION_REQUIRED                    | 428 |\r\n| TOO_MANY_REQUESTS                        | 429 |\r\n| REQUEST_HEADER_FIELDS_TOO_LARGE          | 431 |\r\n| UNAVAILABLE_FOR_LEGAL_REASONS            | 451 |\r\n| INTERNAL_SERVER_ERROR                    | 500 |\r\n| NOT_IMPLEMENTED                          | 501 |\r\n| BAD_GATEWAY                              | 502 |\r\n| SERVICE_UNAVAILABLE                      | 503 |\r\n| GATEWAY_TIMEOUT                          | 504 |\r\n| HTTP_VERSION_NOT_SUPPORTED               | 505 |\r\n| VARIANT_ALSO_NEGOTIATES                  | 506 |\r\n| INSUFFICIENT_STORAGE                     | 507 |\r\n| LOOP_DETECTED                            | 508 |\r\n| NOT_EXTENDED                             | 510 |\r\n| NETWORK_AUTHENTICATION_REQUIRED          | 511 |\r\n\r\n## Usage (JavaScript)\r\nThe following objects are accessible from `statushttp`:\r\n- `statusCode`\r\n   : Textual identifiers mapped to numeric codes.\r\n- `statusText`\r\n   : Numeric codes mapped to textual identifiers.\r\n- `statusDesc`\r\n   : User-friendly status messages/descriptions.\r\n- `statusClass`\r\n   : Enumerations for status classes.\r\n- `StatusCode`\r\n   : A class implementation for status codes to provide ease in working with status codes.\r\n- `sc`\r\n   : An alias for the `StatusCode` class constructor.\r\n\r\nExamples:\r\n``` js\r\nconsole.log(statusCode.NOT_FOUND); // 404\r\nconsole.log(statusText[502]); // BAD_GATEWAY\r\nconsole.log(statusDesc[301]); // Moved Permanently\r\nconsole.log(statusClass.SUCCESS); // 2\r\n```\r\n\r\n### The `StatusCode` class\r\nThe `StatusCode` class provides functionality to facilitate working with HTTP status codes.\r\n\r\nThe class itself is inherited from `String`, and behaves as a user-friendly message string by default.\r\n\r\n#### Constructor\r\nThe constructor receives one parameter, which may be a number representing the status code, or the status text (case-insensitive, with or without the hyphens and parentheses).\r\n\r\nExamples:\r\n``` js\r\nlet   successStatus = new StatusCode(200);\r\n      successStatus = sc(200); // Using the alias\r\nconst createdStatus = sc('created');\r\nconst continueStatus = sc('ConTinUe');\r\n```\r\n\r\n#### Object Properties\r\n- `Code` : The numerical code for the status.\r\n- `Text` : A textual identifier for the status.\r\n- `Desc` : A user-friendly status message.\r\n- `Class` : The status class enumeration for the status (can be matched from `statusClass` properties).\r\n\r\nExamples:\r\n- ``` js\r\n  console.log(successStatus.Text); // OK\r\n\r\n  console.log(createdStatus); // Created\r\n  console.log(createdStatus.Code); // 201\r\n\r\n  console.log(continueStatus.Desc); // Continue\r\n  console.log(continueStatus.Class); // 1\r\n  ```\r\n\r\n## Usage (Command-Line)\r\n`statushttp` can directly be used from the command-line if installed globally. Alterntively, in a project-specific installation, it may be executed using `npx`.\r\n\r\n``` bash\r\nstatushttp \u003cvalue\u003e [options] # Global installation\r\nnpx statushttp \u003cvalue\u003e [options] # Local installation\r\n```\r\n\r\nThe `value` here may be a number representing the status code, or the status text (case-insensitive, with or without the hyphens and parentheses).\r\n\r\nEven if `value` contains spaces, it doesn't need to be sent as one parameter enclosed in quotes.\r\n\r\nOptions:\r\n| Option | Description |\r\n| --- | --- |\r\n| `-l`, `--list` | Show all status codes. |\r\n| `-?`, `--help` | Show help. |\r\n| `-v`, `--version` | Displays the version. |\r\n\r\nExamples:\r\n``` bash\r\n\u003e statushttp ok\r\n\r\nStatus Code: 200\r\nTextual Identifier: OK\r\nMessage: OK\r\nClass: SUCCESS\r\n\r\n\u003e statushttp 304\r\n\r\nStatus Code: 304\r\nTextual Identifier: NOT_MODIFIED\r\nMessage: Not Modified\r\nClass: REDIRECTIONAL\r\n\r\n\u003e statushttp temporary redirect\r\n\r\nStatus Code: 307\r\nTextual Identifier: TEMPORARY_REDIRECT\r\nMessage: Temporary Redirect\r\nClass: REDIRECTIONAL\r\n\r\n\u003e statushttp 'not found'\r\n\r\nStatus Code: 404\r\nTextual Identifier: NOT_FOUND\r\nMessage: Not Found\r\nClass: CLIENT_ERROR\r\n\r\n\u003e statushttp --list\r\n\r\n┌──────┬─────────────────────────────────┐\r\n│ Code │ Message                         │\r\n├──────┼─────────────────────────────────┤\r\n│ 100  │ Continue                        │\r\n├──────┼─────────────────────────────────┤\r\n│ 101  │ Switching Protocols             │\r\n├──────┼─────────────────────────────────┤\r\n│ ...  │ ...                             │\r\n├──────┼─────────────────────────────────┤\r\n│ 510  │ Not Extended                    │\r\n├──────┼─────────────────────────────────┤\r\n│ 511  │ Network Authentication Required │\r\n└──────┴─────────────────────────────────┘\r\n```\r\n\r\n## Examples\r\n- An Express server:\r\n  ``` js\r\n  const express = require('express');\r\n  const cors = require('cors');\r\n  const { statusCode, statusDesc } = require('statushttp');\r\n  \r\n  const app = express();\r\n  \r\n  app.use(cors());\r\n  \r\n  app.route('/*')\r\n  .all((req, res) =\u003e {\r\n  \tres.status(statusCode.NOT_FOUND).end(statusDesc[statusCode.NOT_FOUND]);\r\n  });\r\n  \r\n  app.listen(5000);\r\n  ```\r\n- A React application:\r\n  ``` jsx\r\n  import react, { useState } from 'react';\r\n  import axios from 'axios';\r\n  import { sc } from 'statushttp';\r\n  \r\n  const App = () =\u003e {\r\n    const [resp, setResp] = useState(null);\r\n  \r\n    if (resp == null) {\r\n      axios.get('http://localhost:5000')\r\n        .then(r =\u003e setResp(r))\r\n        .catch(e =\u003e setResp(e.response));\r\n    }\r\n  \r\n    return \u003ch1\u003e{sc(resp?.status || 200)}\u003c/h1\u003e;\r\n  };\r\n  \r\n  export default App;\r\n  ```\r\n\r\n## Development\r\n- Clone the Git repository.\r\n  ``` bash\r\n  git clone https://github.com/paramsiddharth/statushttp.git\r\n  ```\r\n- Install the dependencies.\r\n  ``` bash\r\n  cd statushttp\r\n  npm ci\r\n  ```\r\n- Install the development code as a global module.\r\n  ``` bash\r\n  npm i -g .\r\n  ```\r\n- Build the ESM wrapper and the minified form of the development code.\r\n  ``` bash\r\n  npm run build\r\n  ```\r\n- Test the library.\r\n  ``` bash\r\n  npm test\r\n  ```\r\n  Test with your own values.\r\n  ``` bash\r\n  cd tests\r\n  node test 'service unavailable'\r\n  ```\r\n  Test the minified web version by running `tests/Web.html`.\r\n\r\n## Contribution\r\nContributions are welcome via [GitHub](https://github.com/paramsiddharth/statushttp).\r\n- Raise issues via GitHub.\r\n- Fork the repository.\r\n- Clone the fork.\r\n- Setup the development environment as described above.\r\n- Commit and push changes to the forked repository.\r\n- Create a pull request.\r\n\r\n# Made with ❤ by [Param](http://www.paramsid.com).\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparamsiddharth%2Fstatushttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparamsiddharth%2Fstatushttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparamsiddharth%2Fstatushttp/lists"}