Comparing version 1.2.1 to 1.3.0
@@ -43,2 +43,3 @@ { | ||
"418": "I'm a teapot", | ||
"421": "Misdirected Request", | ||
"422": "Unprocessable Entity", | ||
@@ -45,0 +46,0 @@ "423": "Locked", |
100
index.js
@@ -0,15 +1,27 @@ | ||
/*! | ||
* statuses | ||
* Copyright(c) 2014 Jonathan Ong | ||
* Copyright(c) 2016 Douglas Christopher Wilson | ||
* MIT Licensed | ||
*/ | ||
var codes = require('./codes.json'); | ||
'use strict' | ||
module.exports = status; | ||
/** | ||
* Module dependencies. | ||
* @private | ||
*/ | ||
// [Integer...] | ||
status.codes = Object.keys(codes).map(function (code) { | ||
code = ~~code; | ||
var msg = codes[code]; | ||
status[code] = msg; | ||
status[msg] = status[msg.toLowerCase()] = code; | ||
return code; | ||
}); | ||
var codes = require('./codes.json') | ||
/** | ||
* Module exports. | ||
* @public | ||
*/ | ||
module.exports = status | ||
// array of status codes | ||
status.codes = populateStatusesMap(status, codes) | ||
// status codes for redirects | ||
@@ -23,4 +35,4 @@ status.redirect = { | ||
307: true, | ||
308: true, | ||
}; | ||
308: true | ||
} | ||
@@ -31,4 +43,4 @@ // status codes for empty bodies | ||
205: true, | ||
304: true, | ||
}; | ||
304: true | ||
} | ||
@@ -39,13 +51,51 @@ // status codes for when you should retry the request | ||
503: true, | ||
504: true, | ||
}; | ||
504: true | ||
} | ||
function status(code) { | ||
/** | ||
* Populate the statuses map for given codes. | ||
* @private | ||
*/ | ||
function populateStatusesMap (statuses, codes) { | ||
var arr = [] | ||
Object.keys(codes).forEach(function forEachCode (code) { | ||
var message = codes[code] | ||
var status = Number(code) | ||
// Populate properties | ||
statuses[status] = message | ||
statuses[message] = status | ||
statuses[message.toLowerCase()] = status | ||
// Add to array | ||
arr.push(status) | ||
}) | ||
return arr | ||
} | ||
/** | ||
* Get the status code. | ||
* | ||
* Given 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. | ||
* | ||
* @param {string|number} code | ||
* @returns {string} | ||
* @public | ||
*/ | ||
function status (code) { | ||
if (typeof code === 'number') { | ||
if (!status[code]) throw new Error('invalid status code: ' + code); | ||
return code; | ||
if (!status[code]) throw new Error('invalid status code: ' + code) | ||
return code | ||
} | ||
if (typeof code !== 'string') { | ||
throw new TypeError('code must be a number or string'); | ||
throw new TypeError('code must be a number or string') | ||
} | ||
@@ -56,9 +106,9 @@ | ||
if (!isNaN(n)) { | ||
if (!status[n]) throw new Error('invalid status code: ' + n); | ||
return n; | ||
if (!status[n]) throw new Error('invalid status code: ' + n) | ||
return n | ||
} | ||
n = status[code.toLowerCase()]; | ||
if (!n) throw new Error('invalid status message: "' + code + '"'); | ||
return n; | ||
n = status[code.toLowerCase()] | ||
if (!n) throw new Error('invalid status message: "' + code + '"') | ||
return n | ||
} |
{ | ||
"name": "statuses", | ||
"description": "HTTP status utility", | ||
"version": "1.2.1", | ||
"author": { | ||
"name": "Jonathan Ong", | ||
"email": "me@jongleberry.com", | ||
"url": "http://jongleberry.com", | ||
"twitter": "https://twitter.com/jongleberry" | ||
}, | ||
"version": "1.3.0", | ||
"contributors": [ | ||
"Douglas Christopher Wilson <doug@somethingdoug.com>", | ||
"Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)" | ||
], | ||
"repository": "jshttp/statuses", | ||
@@ -19,2 +17,3 @@ "license": "MIT", | ||
"files": [ | ||
"HISTORY.md", | ||
"index.js", | ||
@@ -25,14 +24,23 @@ "codes.json", | ||
"devDependencies": { | ||
"csv-parse": "0.0.6", | ||
"istanbul": "0", | ||
"mocha": "1", | ||
"stream-to-array": "2" | ||
"csv-parse": "1.0.1", | ||
"eslint": "2.10.2", | ||
"eslint-config-standard": "5.3.1", | ||
"eslint-plugin-promise": "1.1.0", | ||
"eslint-plugin-standard": "1.3.2", | ||
"istanbul": "0.4.3", | ||
"mocha": "1.21.5", | ||
"stream-to-array": "2.2.0" | ||
}, | ||
"engines": { | ||
"node": ">= 0.6" | ||
}, | ||
"scripts": { | ||
"build": "node scripts/build.js", | ||
"update": "node scripts/update.js", | ||
"test": "mocha --reporter spec --bail --check-leaks", | ||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks", | ||
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks" | ||
"fetch": "node scripts/fetch.js", | ||
"lint": "eslint **/*.js", | ||
"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" | ||
} | ||
} |
@@ -14,3 +14,3 @@ # Statuses | ||
```js | ||
var status = require('statuses'); | ||
var status = require('statuses') | ||
``` | ||
@@ -23,4 +23,4 @@ | ||
```js | ||
status(403) // => 'Forbidden' | ||
status('403') // => 'Forbidden' | ||
status(403) // => 403 | ||
status('403') // => 403 | ||
status('forbidden') // => 403 | ||
@@ -83,3 +83,3 @@ status('Forbidden') // => 403 | ||
```js | ||
var codes = require('statuses/codes.json'); | ||
var codes = require('statuses/codes.json') | ||
``` | ||
@@ -103,3 +103,3 @@ | ||
# update src/iana.json | ||
npm run update | ||
npm run fetch | ||
# build codes.json | ||
@@ -109,11 +109,11 @@ npm run build | ||
[npm-image]: https://img.shields.io/npm/v/statuses.svg?style=flat | ||
[npm-image]: https://img.shields.io/npm/v/statuses.svg | ||
[npm-url]: https://npmjs.org/package/statuses | ||
[node-version-image]: http://img.shields.io/badge/node.js-%3E%3D_0.6-brightgreen.svg?style=flat | ||
[node-version-url]: http://nodejs.org/download/ | ||
[travis-image]: https://img.shields.io/travis/jshttp/statuses.svg?style=flat | ||
[node-version-image]: https://img.shields.io/badge/node.js-%3E%3D_0.6-brightgreen.svg | ||
[node-version-url]: https://nodejs.org/en/download | ||
[travis-image]: https://img.shields.io/travis/jshttp/statuses.svg | ||
[travis-url]: https://travis-ci.org/jshttp/statuses | ||
[coveralls-image]: https://img.shields.io/coveralls/jshttp/statuses.svg?style=flat | ||
[coveralls-image]: https://img.shields.io/coveralls/jshttp/statuses.svg | ||
[coveralls-url]: https://coveralls.io/r/jshttp/statuses?branch=master | ||
[downloads-image]: http://img.shields.io/npm/dm/statuses.svg?style=flat | ||
[downloads-image]: https://img.shields.io/npm/dm/statuses.svg | ||
[downloads-url]: https://npmjs.org/package/statuses |
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
10044
6
154
0
8