{"id":18317925,"url":"https://github.com/idiocc/statuses","last_synced_at":"2025-04-09T13:51:29.863Z","repository":{"id":57113721,"uuid":"227718616","full_name":"idiocc/statuses","owner":"idiocc","description":"HTTP status utility.","archived":false,"fork":false,"pushed_at":"2019-12-13T21:20:49.000Z","size":81,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-17T23:24:36.777Z","etag":null,"topics":["goa","http","idio","status"],"latest_commit_sha":null,"homepage":"https://www.idio.cc","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/idiocc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-12T23:59:40.000Z","updated_at":"2019-12-13T21:20:51.000Z","dependencies_parsed_at":"2022-08-22T05:10:08.392Z","dependency_job_id":null,"html_url":"https://github.com/idiocc/statuses","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":"mnpjs/package","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fstatuses","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fstatuses/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fstatuses/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fstatuses/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idiocc","download_url":"https://codeload.github.com/idiocc/statuses/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248054218,"owners_count":21039951,"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":["goa","http","idio","status"],"created_at":"2024-11-05T18:07:54.010Z","updated_at":"2025-04-09T13:51:29.845Z","avatar_url":"https://github.com/idiocc.png","language":"JavaScript","readme":"# @goa/statuses\n\n[![npm version](https://badge.fury.io/js/%40goa%2Fstatuses.svg)](https://www.npmjs.com/package/@goa/statuses)\n\n`@goa/statuses` is HTTP status utility.\n\n```sh\nyarn add @goa/statuses\n```\n\n## Table Of Contents\n\n- [Table Of Contents](#table-of-contents)\n- [API](#api)\n- [`status(code: number|string): number`](#statuscode-numberstring-number)\n- [Codes Objects](#codes-objects)\n  * [`STATUS_CODES`](#type-status_codes)\n  * [`codes`](#type-codes)\n  * [status[code]](#statuscode)\n  * [status[message]](#statusmessage)\n  * [redirect[code]](#redirectcode)\n  * [empty[code]](#emptycode)\n  * [retry[code]](#retrycode)\n- [Copyright \u0026 License](#copyright--license)\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/0.svg?sanitize=true\"\u003e\n\u003c/a\u003e\u003c/p\u003e\n\n## API\n\nThe package is available by importing its default function and additional objects populated with status codes:\n\n```js\nimport status, { STATUS_CODES } from '@goa/statuses'\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/1.svg?sanitize=true\"\u003e\n\u003c/a\u003e\u003c/p\u003e\n\n## \u003ccode\u003e\u003cins\u003estatus\u003c/ins\u003e(\u003c/code\u003e\u003csub\u003e\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`code: number|string,`\u003cbr/\u003e\u003c/sub\u003e\u003ccode\u003e): \u003ci\u003enumber\u003c/i\u003e\u003c/code\u003e\nGet the status code.\n\nGiven a number, this will throw if it is not a known status code, otherwise the code will be returned. Given a string, the string will be parsed for a number and return the code if valid, otherwise will lookup the code assuming this is the status message.\n\n - \u003ckbd\u003e\u003cstrong\u003ecode*\u003c/strong\u003e\u003c/kbd\u003e \u003cem\u003e\u003ccode\u003e(number \\| string)\u003c/code\u003e\u003c/em\u003e: The code or phrase.\n\n```js\nimport status from '@goa/statuses'\n\nconsole.log(status(403)) // =\u003e 403\nconsole.log(status('403')) // =\u003e 403\nconsole.log(status('forbidden')) // =\u003e 403\nconsole.log(status('Forbidden')) // =\u003e 403\ntry {\n  status(5000) // throws, as it's not supported by Node.JS\n} catch (err) {\n  console.log(err.message)\n}\n```\n```\n403\n403\n403\n403\ninvalid status code: 5000\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/2.svg?sanitize=true\"\u003e\n\u003c/a\u003e\u003c/p\u003e\n\n## Codes Objects\n\nAdditional exports are populated with codes directly.\n\n\n\u003ccode\u003e!Object\u0026lt;string, string\u0026gt;\u003c/code\u003e \u003cstrong\u003e\u003ca name=\"type-status_codes\"\u003e`STATUS_CODES`\u003c/a\u003e\u003c/strong\u003e\n\nReturns an object which maps status codes to status messages, in the same format as the [Node.JS](https://nodejs.org/dist/latest/docs/api/http.html#http_http_status_codes) `http` module.\n\n```js\nimport { STATUS_CODES } from '@goa/statuses'\n\nconsole.log(STATUS_CODES)\n```\n```js\n{ '100': 'Continue',\n  '101': 'Switching Protocols',\n  '102': 'Processing',\n  '103': 'Early Hints',\n  '200': 'OK',\n  '201': 'Created',\n  '202': 'Accepted',\n  '203': 'Non-Authoritative Information',\n  '204': 'No Content',\n  '205': 'Reset Content',\n  '206': 'Partial Content',\n  '207': 'Multi-Status',\n  '208': 'Already Reported',\n  '226': 'IM Used',\n  '300': 'Multiple Choices',\n  '301': 'Moved Permanently',\n  '302': 'Found',\n  '303': 'See Other',\n  '304': 'Not Modified',\n  '305': 'Use Proxy',\n  '306': '(Unused)',\n  '307': 'Temporary Redirect',\n  '308': 'Permanent Redirect',\n  '400': 'Bad Request',\n  '401': 'Unauthorized',\n  '402': 'Payment Required',\n  '403': 'Forbidden',\n  '404': 'Not Found',\n  '405': 'Method Not Allowed',\n  '406': 'Not Acceptable',\n  '407': 'Proxy Authentication Required',\n  '408': 'Request Timeout',\n  '409': 'Conflict',\n  '410': 'Gone',\n  '411': 'Length Required',\n  '412': 'Precondition Failed',\n  '413': 'Payload Too Large',\n  '414': 'URI Too Long',\n  '415': 'Unsupported Media Type',\n  '416': 'Range Not Satisfiable',\n  '417': 'Expectation Failed',\n  '418': 'I\\'m a teapot',\n  '421': 'Misdirected Request',\n  '422': 'Unprocessable Entity',\n  '423': 'Locked',\n  '424': 'Failed Dependency',\n  '425': 'Unordered Collection',\n  '426': 'Upgrade Required',\n  '428': 'Precondition Required',\n  '429': 'Too Many Requests',\n  '431': 'Request Header Fields Too Large',\n  '451': 'Unavailable For Legal Reasons',\n  '500': 'Internal Server Error',\n  '501': 'Not Implemented',\n  '502': 'Bad Gateway',\n  '503': 'Service Unavailable',\n  '504': 'Gateway Timeout',\n  '505': 'HTTP Version Not Supported',\n  '506': 'Variant Also Negotiates',\n  '507': 'Insufficient Storage',\n  '508': 'Loop Detected',\n  '509': 'Bandwidth Limit Exceeded',\n  '510': 'Not Extended',\n  '511': 'Network Authentication Required' }\n```\n\n\n\u003ccode\u003e!Array\u0026lt;number\u0026gt;\u003c/code\u003e __\u003ca name=\"type-codes\"\u003e`codes`\u003c/a\u003e__\n\nReturns an array of all the status codes as numbers.\n\n```js\nimport { codes } from '@goa/statuses'\n\nconsole.log(codes)\n```\n```js\n[ 100,\n  101,\n  102,\n  103,\n  200,\n  201,\n  202,\n  203,\n  204,\n  205,\n  206,\n  207,\n  208,\n  226,\n  300,\n  301,\n  302,\n  303,\n  304,\n  305,\n  306,\n  307,\n  308,\n  400,\n  401,\n  402,\n  403,\n  404,\n  405,\n  406,\n  407,\n  408,\n  409,\n  410,\n  411,\n  412,\n  413,\n  414,\n  415,\n  416,\n  417,\n  418,\n  421,\n  422,\n  423,\n  424,\n  425,\n  426,\n  428,\n  429,\n  431,\n  451,\n  500,\n  501,\n  502,\n  503,\n  504,\n  505,\n  506,\n  507,\n  508,\n  509,\n  510,\n  511 ]\n```\n\n### status[code]\n\nMap of `code` to `status message`. Returns `undefined` for invalid codes.\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003e\u003ca href=\"example/code.js\"\u003eSource\u003c/a\u003e\u003c/th\u003e\u003cth\u003eOutput\u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```js\nimport status from '@goa/statuses'\n\nconsole.log(status[404])\n```\n\u003c/td\u003e\n\u003ctd\u003e\n\n```js\n​\n\nNot Found\n```\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n### status[message]\n\nMap of `status message` to `code`. `msg` can either be title-cased or lower-cased. Returns `undefined` for invalid status messages.\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003e\u003ca href=\"example/message.js\"\u003eSource\u003c/a\u003e\u003c/th\u003e\u003cth\u003eOutput\u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```js\nimport status from '@goa/statuses'\n\nconsole.log(status['not found'])\nconsole.log(status['Not Found'])\n```\n\u003c/td\u003e\n\u003ctd\u003e\n\n```js\n​\n\n404\n404\n```\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n### redirect[code]\n\nReturns `true` if a status code is a valid redirect status.\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003e\u003ca href=\"example/redirect.js\"\u003eSource\u003c/a\u003e\u003c/th\u003e\u003cth\u003eOutput\u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```js\nimport { redirect } from '@goa/statuses'\n\nconsole.log(redirect[200])\nconsole.log(redirect[301])\n```\n\u003c/td\u003e\n\u003ctd\u003e\n\n```js\n​\n\nundefined\ntrue\n```\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n### empty[code]\n\nReturns `true` if a status code expects an empty body.\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003e\u003ca href=\"example/empty.js\"\u003eSource\u003c/a\u003e\u003c/th\u003e\u003cth\u003eOutput\u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```js\nimport { empty } from '@goa/statuses'\n\nconsole.log(empty[200])\nconsole.log(empty[204])\nconsole.log(empty[304])\n```\n\u003c/td\u003e\n\u003ctd\u003e\n\n```js\n​\n\nundefined\ntrue\ntrue\n```\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n### retry[code]\n\nReturns `true` if you should retry the rest.\n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003e\u003ca href=\"example/retry.js\"\u003eSource\u003c/a\u003e\u003c/th\u003e\u003cth\u003eOutput\u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```js\nimport { retry } from '@goa/statuses'\n\nconsole.log(retry[501])\nconsole.log(retry[503])\n```\n\u003c/td\u003e\n\u003ctd\u003e\n\n```js\n​\n\nundefined\ntrue\n```\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/3.svg?sanitize=true\"\u003e\n\u003c/a\u003e\u003c/p\u003e\n\n## Copyright \u0026 License\n\nGNU Affero General Public License v3.0\n\n[Original work](https://github.com/jshttp/statuses#readme) by Jonathan Ong and Douglas Christopher Wilson under MIT license found in [COPYING](COPYING).\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/40834161?s=100\u0026amp;v=4\" alt=\"idiocc\"\u003e\u003c/td\u003e\n    \u003ctd\u003e© \u003ca href=\"https://www.artd.eco\"\u003eArt Deco™\u003c/a\u003e 2019\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\n  \u003cimg src=\"/.documentary/section-breaks/-1.svg?sanitize=true\"\u003e\n\u003c/a\u003e\u003c/p\u003e","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiocc%2Fstatuses","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidiocc%2Fstatuses","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiocc%2Fstatuses/lists"}