Comparing version 1.5.0 to 2.0.0
@@ -22,3 +22,2 @@ { | ||
"305": "Use Proxy", | ||
"306": "(Unused)", | ||
"307": "Temporary Redirect", | ||
@@ -44,3 +43,3 @@ "308": "Permanent Redirect", | ||
"417": "Expectation Failed", | ||
"418": "I'm a teapot", | ||
"418": "I'm a Teapot", | ||
"421": "Misdirected Request", | ||
@@ -50,3 +49,3 @@ "422": "Unprocessable Entity", | ||
"424": "Failed Dependency", | ||
"425": "Unordered Collection", | ||
"425": "Too Early", | ||
"426": "Upgrade Required", | ||
@@ -53,0 +52,0 @@ "428": "Precondition Required", |
@@ -0,1 +1,13 @@ | ||
2.0.0 / 2020-04-19 | ||
================== | ||
* Drop support for Node.js 0.6 | ||
* Fix messaging casing of `418 I'm a Teapot` | ||
* Remove code 306 | ||
* Remove `status[code]` exports; use `status.message[code]` | ||
* Remove `status[msg]` exports; use `status.code[msg]` | ||
* Rename `425 Unordered Collection` to standard `425 Too Early` | ||
* Rename `STATUS_CODES` export to `message` | ||
* Return status message for `statuses(code)` when given code | ||
1.5.0 / 2018-03-27 | ||
@@ -2,0 +14,0 @@ ================== |
45
index.js
@@ -25,6 +25,9 @@ /*! | ||
// status code to message map | ||
status.STATUS_CODES = codes | ||
status.message = codes | ||
// status message (lower-case) to code map | ||
status.code = createMessageToStatusCodeMap(codes) | ||
// array of status codes | ||
status.codes = populateStatusesMap(status, codes) | ||
status.codes = createStatusCodeList(codes) | ||
@@ -57,8 +60,8 @@ // status codes for redirects | ||
/** | ||
* Populate the statuses map for given codes. | ||
* Create a map of message to status code. | ||
* @private | ||
*/ | ||
function populateStatusesMap (statuses, codes) { | ||
var arr = [] | ||
function createMessageToStatusCodeMap (codes) { | ||
var map = {} | ||
@@ -69,15 +72,21 @@ Object.keys(codes).forEach(function forEachCode (code) { | ||
// Populate properties | ||
statuses[status] = message | ||
statuses[message] = status | ||
statuses[message.toLowerCase()] = status | ||
// Add to array | ||
arr.push(status) | ||
// populate map | ||
map[message.toLowerCase()] = status | ||
}) | ||
return arr | ||
return map | ||
} | ||
/** | ||
* Create a list of all status codes. | ||
* @private | ||
*/ | ||
function createStatusCodeList (codes) { | ||
return Object.keys(codes).map(function mapCode (code) { | ||
return Number(code) | ||
}) | ||
} | ||
/** | ||
* Get the status code. | ||
@@ -98,4 +107,4 @@ * | ||
if (typeof code === 'number') { | ||
if (!status[code]) throw new Error('invalid status code: ' + code) | ||
return code | ||
if (!status.message[code]) throw new Error('invalid status code: ' + code) | ||
return status.message[code] | ||
} | ||
@@ -110,9 +119,9 @@ | ||
if (!isNaN(n)) { | ||
if (!status[n]) throw new Error('invalid status code: ' + n) | ||
return n | ||
if (!status.message[n]) throw new Error('invalid status code: ' + n) | ||
return status.message[n] | ||
} | ||
n = status[code.toLowerCase()] | ||
n = status.code[code.toLowerCase()] | ||
if (!n) throw new Error('invalid status message: "' + code + '"') | ||
return n | ||
} |
{ | ||
"name": "statuses", | ||
"description": "HTTP status utility", | ||
"version": "1.5.0", | ||
"version": "2.0.0", | ||
"contributors": [ | ||
@@ -23,17 +23,17 @@ "Douglas Christopher Wilson <doug@somethingdoug.com>", | ||
"devDependencies": { | ||
"csv-parse": "1.2.4", | ||
"eslint": "4.19.1", | ||
"eslint-config-standard": "11.0.0", | ||
"eslint-plugin-import": "2.9.0", | ||
"eslint-plugin-markdown": "1.0.0-beta.6", | ||
"eslint-plugin-node": "6.0.1", | ||
"eslint-plugin-promise": "3.7.0", | ||
"eslint-plugin-standard": "3.0.1", | ||
"istanbul": "0.4.5", | ||
"mocha": "1.21.5", | ||
"raw-body": "2.3.2", | ||
"csv-parse": "4.8.8", | ||
"eslint": "6.8.0", | ||
"eslint-config-standard": "14.1.1", | ||
"eslint-plugin-import": "2.20.2", | ||
"eslint-plugin-markdown": "1.0.2", | ||
"eslint-plugin-node": "11.1.0", | ||
"eslint-plugin-promise": "4.2.1", | ||
"eslint-plugin-standard": "4.0.1", | ||
"mocha": "7.1.1", | ||
"nyc": "15.0.1", | ||
"raw-body": "2.4.1", | ||
"stream-to-array": "2.3.0" | ||
}, | ||
"engines": { | ||
"node": ">= 0.6" | ||
"node": ">= 0.8" | ||
}, | ||
@@ -45,6 +45,7 @@ "scripts": { | ||
"test": "mocha --reporter spec --check-leaks --bail test/", | ||
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/", | ||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", | ||
"update": "npm run fetch && npm run build" | ||
"test-ci": "nyc --reporter=text npm test", | ||
"test-cov": "nyc --reporter=html --reporter=text npm test", | ||
"update": "npm run fetch && npm run build", | ||
"version": "node scripts/version-history.js && git add HISTORY.md" | ||
} | ||
} |
@@ -1,5 +0,5 @@ | ||
# Statuses | ||
# statuses | ||
[![NPM Version][npm-image]][npm-url] | ||
[![NPM Downloads][downloads-image]][downloads-url] | ||
[![NPM Version][npm-version-image]][npm-url] | ||
[![NPM Downloads][npm-downloads-image]][npm-url] | ||
[![Node.js Version][node-version-image]][node-version-url] | ||
@@ -37,6 +37,6 @@ [![Build Status][travis-image]][travis-url] | ||
### var code = status(Integer || String) | ||
### status(code) | ||
If `Integer` or `String` is a valid HTTP code or status message, then the | ||
appropriate `code` will be returned. Otherwise, an error will be thrown. | ||
Returns the status message string for a known HTTP status code. The code | ||
may be a number or a string. An error is thrown for an unknown status code. | ||
@@ -46,15 +46,20 @@ <!-- eslint-disable no-undef --> | ||
```js | ||
status(403) // => 403 | ||
status('403') // => 403 | ||
status(403) // => 'Forbidden' | ||
status('403') // => 'Forbidden' | ||
status(306) // throws | ||
``` | ||
### status(msg) | ||
Returns the numeric status code for a known HTTP status message. The message | ||
is case-insensitive. An error is thrown for an unknown status message. | ||
<!-- eslint-disable no-undef --> | ||
```js | ||
status('forbidden') // => 403 | ||
status('Forbidden') // => 403 | ||
status(306) // throws, as it's not supported by node.js | ||
status('foo') // throws | ||
``` | ||
### status.STATUS_CODES | ||
Returns an object which maps status codes to status messages, in | ||
the same format as the | ||
[Node.js http module](https://nodejs.org/dist/latest/docs/api/http.html#http_http_status_codes). | ||
### status.codes | ||
@@ -64,5 +69,6 @@ | ||
### var msg = status[code] | ||
### status.code[msg] | ||
Map of `code` to `status message`. `undefined` for invalid `code`s. | ||
Returns the numeric status code for a known status message (in lower-case), | ||
otherwise `undefined`. | ||
@@ -72,9 +78,8 @@ <!-- eslint-disable no-undef, no-unused-expressions --> | ||
```js | ||
status[404] // => 'Not Found' | ||
status['not found'] // => 404 | ||
``` | ||
### var code = status[msg] | ||
### status.empty[code] | ||
Map of `status message` to `code`. `msg` can either be title-cased or | ||
lower-cased. `undefined` for invalid `status message`s. | ||
Returns `true` if a status code expects an empty body. | ||
@@ -84,9 +89,12 @@ <!-- eslint-disable no-undef, no-unused-expressions --> | ||
```js | ||
status['not found'] // => 404 | ||
status['Not Found'] // => 404 | ||
status.empty[200] // => undefined | ||
status.empty[204] // => true | ||
status.empty[304] // => true | ||
``` | ||
### status.redirect[code] | ||
### status.message[code] | ||
Returns `true` if a status code is a valid redirect status. | ||
Returns the string message for a known numeric status code, otherwise | ||
`undefined`. This object is the same format as the | ||
[Node.js http module `http.STATUS_CODES`](https://nodejs.org/dist/latest/docs/api/http.html#http_http_status_codes). | ||
@@ -96,9 +104,8 @@ <!-- eslint-disable no-undef, no-unused-expressions --> | ||
```js | ||
status.redirect[200] // => undefined | ||
status.redirect[301] // => true | ||
status.message[404] // => 'Not Found' | ||
``` | ||
### status.empty[code] | ||
### status.redirect[code] | ||
Returns `true` if a status code expects an empty body. | ||
Returns `true` if a status code is a valid redirect status. | ||
@@ -108,5 +115,4 @@ <!-- eslint-disable no-undef, no-unused-expressions --> | ||
```js | ||
status.empty[200] // => undefined | ||
status.empty[204] // => true | ||
status.empty[304] // => true | ||
status.redirect[200] // => undefined | ||
status.redirect[301] // => true | ||
``` | ||
@@ -125,11 +131,14 @@ | ||
[npm-image]: https://img.shields.io/npm/v/statuses.svg | ||
## License | ||
[MIT](LICENSE) | ||
[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/statuses/master | ||
[coveralls-url]: https://coveralls.io/r/jshttp/statuses?branch=master | ||
[node-version-image]: https://badgen.net/npm/node/statuses | ||
[node-version-url]: https://nodejs.org/en/download | ||
[npm-downloads-image]: https://badgen.net/npm/dm/statuses | ||
[npm-url]: https://npmjs.org/package/statuses | ||
[node-version-image]: https://img.shields.io/node/v/statuses.svg | ||
[node-version-url]: https://nodejs.org/en/download | ||
[travis-image]: https://img.shields.io/travis/jshttp/statuses.svg | ||
[npm-version-image]: https://badgen.net/npm/v/statuses | ||
[travis-image]: https://badgen.net/travis/jshttp/statuses/master | ||
[travis-url]: https://travis-ci.org/jshttp/statuses | ||
[coveralls-image]: https://img.shields.io/coveralls/jshttp/statuses.svg | ||
[coveralls-url]: https://coveralls.io/r/jshttp/statuses?branch=master | ||
[downloads-image]: https://img.shields.io/npm/dm/statuses.svg | ||
[downloads-url]: https://npmjs.org/package/statuses |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11666
164
137