pax_global_header00006660000000000000000000000064132565714000014515gustar00rootroot0000000000000052 comment=4fcf6fb80ef50e8f0603b87946b0fa7868c815e7 statuses-1.5.0/000077500000000000000000000000001325657140000133735ustar00rootroot00000000000000statuses-1.5.0/.eslintignore000066400000000000000000000000261325657140000160740ustar00rootroot00000000000000coverage node_modules statuses-1.5.0/.eslintrc000066400000000000000000000000341325657140000152140ustar00rootroot00000000000000{ "extends": "standard" } statuses-1.5.0/.gitignore000066400000000000000000000002511325657140000153610ustar00rootroot00000000000000# OS X .DS_Store* Icon? ._* # Windows Thumbs.db ehthumbs.db Desktop.ini # Linux .directory *~ # npm node_modules package-lock.json *.log *.gz # Coveralls coverage statuses-1.5.0/.travis.yml000066400000000000000000000023561325657140000155120ustar00rootroot00000000000000language: node_js node_js: - "0.6" - "0.8" - "0.10" - "0.12" - "1.8" - "2.5" - "3.3" - "4.8" - "5.12" - "6.13" - "7.10" - "8.10" - "9.9" sudo: false dist: precise cache: directories: - node_modules before_install: # Skip updating shrinkwrap / lock - "npm config set shrinkwrap false" # Remove all non-test dependencies - "npm rm --save-dev csv-parse" - "npm rm --save-dev raw-body" - "npm rm --save-dev stream-to-array" # Setup Node.js version-specific dependencies - "test $TRAVIS_NODE_VERSION != '0.6' || npm rm --save-dev istanbul" - "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul" - "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 4 || npm rm --save-dev $(grep -E '\"eslint\\S*\"' package.json | cut -d'\"' -f2)" # Update Node.js modules - "test ! -d node_modules || npm prune" - "test ! -d node_modules || npm rebuild" script: # Run test script, depending on istanbul install - "test ! -z $(npm -ps ls istanbul) || npm test" - "test -z $(npm -ps ls istanbul) || npm run-script test-ci" - "test -z $(npm -ps ls eslint ) || npm run-script lint" after_script: - "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls" statuses-1.5.0/HISTORY.md000066400000000000000000000017771325657140000150720ustar00rootroot000000000000001.5.0 / 2018-03-27 ================== * Add `103 Early Hints` 1.4.0 / 2017-10-20 ================== * Add `STATUS_CODES` export 1.3.1 / 2016-11-11 ================== * Fix return type in JSDoc 1.3.0 / 2016-05-17 ================== * Add `421 Misdirected Request` * perf: enable strict mode 1.2.1 / 2015-02-01 ================== * Fix message for status 451 - `451 Unavailable For Legal Reasons` 1.2.0 / 2014-09-28 ================== * Add `208 Already Repored` * Add `226 IM Used` * Add `306 (Unused)` * Add `415 Unable For Legal Reasons` * Add `508 Loop Detected` 1.1.1 / 2014-09-24 ================== * Add missing 308 to `codes.json` 1.1.0 / 2014-09-21 ================== * Add `codes.json` for universal support 1.0.4 / 2014-08-20 ================== * Package cleanup 1.0.3 / 2014-06-08 ================== * Add 308 to `.redirect` category 1.0.2 / 2014-03-13 ================== * Add `.retry` category 1.0.1 / 2014-03-12 ================== * Initial release statuses-1.5.0/LICENSE000066400000000000000000000022241325657140000144000ustar00rootroot00000000000000 The MIT License (MIT) Copyright (c) 2014 Jonathan Ong Copyright (c) 2016 Douglas Christopher Wilson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. statuses-1.5.0/README.md000066400000000000000000000066021325657140000146560ustar00rootroot00000000000000# Statuses [![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url] [![Node.js Version][node-version-image]][node-version-url] [![Build Status][travis-image]][travis-url] [![Test Coverage][coveralls-image]][coveralls-url] HTTP status utility for node. This module provides a list of status codes and messages sourced from a few different projects: * The [IANA Status Code Registry](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml) * The [Node.js project](https://nodejs.org/) * The [NGINX project](https://www.nginx.com/) * The [Apache HTTP Server project](https://httpd.apache.org/) ## Installation This is a [Node.js](https://nodejs.org/en/) module available through the [npm registry](https://www.npmjs.com/). Installation is done using the [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): ```sh $ npm install statuses ``` ## API ```js var status = require('statuses') ``` ### var code = status(Integer || String) 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. ```js status(403) // => 403 status('403') // => 403 status('forbidden') // => 403 status('Forbidden') // => 403 status(306) // throws, as it's not supported by node.js ``` ### 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 Returns an array of all the status codes as `Integer`s. ### var msg = status[code] Map of `code` to `status message`. `undefined` for invalid `code`s. ```js status[404] // => 'Not Found' ``` ### var code = status[msg] Map of `status message` to `code`. `msg` can either be title-cased or lower-cased. `undefined` for invalid `status message`s. ```js status['not found'] // => 404 status['Not Found'] // => 404 ``` ### status.redirect[code] Returns `true` if a status code is a valid redirect status. ```js status.redirect[200] // => undefined status.redirect[301] // => true ``` ### status.empty[code] Returns `true` if a status code expects an empty body. ```js status.empty[200] // => undefined status.empty[204] // => true status.empty[304] // => true ``` ### status.retry[code] Returns `true` if you should retry the rest. ```js status.retry[501] // => undefined status.retry[503] // => true ``` [npm-image]: https://img.shields.io/npm/v/statuses.svg [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 [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 statuses-1.5.0/codes.json000066400000000000000000000034351325657140000153700ustar00rootroot00000000000000{ "100": "Continue", "101": "Switching Protocols", "102": "Processing", "103": "Early Hints", "200": "OK", "201": "Created", "202": "Accepted", "203": "Non-Authoritative Information", "204": "No Content", "205": "Reset Content", "206": "Partial Content", "207": "Multi-Status", "208": "Already Reported", "226": "IM Used", "300": "Multiple Choices", "301": "Moved Permanently", "302": "Found", "303": "See Other", "304": "Not Modified", "305": "Use Proxy", "306": "(Unused)", "307": "Temporary Redirect", "308": "Permanent Redirect", "400": "Bad Request", "401": "Unauthorized", "402": "Payment Required", "403": "Forbidden", "404": "Not Found", "405": "Method Not Allowed", "406": "Not Acceptable", "407": "Proxy Authentication Required", "408": "Request Timeout", "409": "Conflict", "410": "Gone", "411": "Length Required", "412": "Precondition Failed", "413": "Payload Too Large", "414": "URI Too Long", "415": "Unsupported Media Type", "416": "Range Not Satisfiable", "417": "Expectation Failed", "418": "I'm a teapot", "421": "Misdirected Request", "422": "Unprocessable Entity", "423": "Locked", "424": "Failed Dependency", "425": "Unordered Collection", "426": "Upgrade Required", "428": "Precondition Required", "429": "Too Many Requests", "431": "Request Header Fields Too Large", "451": "Unavailable For Legal Reasons", "500": "Internal Server Error", "501": "Not Implemented", "502": "Bad Gateway", "503": "Service Unavailable", "504": "Gateway Timeout", "505": "HTTP Version Not Supported", "506": "Variant Also Negotiates", "507": "Insufficient Storage", "508": "Loop Detected", "509": "Bandwidth Limit Exceeded", "510": "Not Extended", "511": "Network Authentication Required" } statuses-1.5.0/index.js000066400000000000000000000040501325657140000150370ustar00rootroot00000000000000/*! * statuses * Copyright(c) 2014 Jonathan Ong * Copyright(c) 2016 Douglas Christopher Wilson * MIT Licensed */ 'use strict' /** * Module dependencies. * @private */ var codes = require('./codes.json') /** * Module exports. * @public */ module.exports = status // status code to message map status.STATUS_CODES = codes // array of status codes status.codes = populateStatusesMap(status, codes) // status codes for redirects status.redirect = { 300: true, 301: true, 302: true, 303: true, 305: true, 307: true, 308: true } // status codes for empty bodies status.empty = { 204: true, 205: true, 304: true } // status codes for when you should retry the request status.retry = { 502: true, 503: true, 504: true } /** * 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 {number} * @public */ function status (code) { if (typeof code === 'number') { 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') } // '403' var n = parseInt(code, 10) if (!isNaN(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 } statuses-1.5.0/package.json000066400000000000000000000027001325657140000156600ustar00rootroot00000000000000{ "name": "statuses", "description": "HTTP status utility", "version": "1.5.0", "contributors": [ "Douglas Christopher Wilson ", "Jonathan Ong (http://jongleberry.com)" ], "repository": "jshttp/statuses", "license": "MIT", "keywords": [ "http", "status", "code" ], "files": [ "HISTORY.md", "index.js", "codes.json", "LICENSE" ], "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", "stream-to-array": "2.3.0" }, "engines": { "node": ">= 0.6" }, "scripts": { "build": "node scripts/build.js", "fetch": "node scripts/fetch-apache.js && node scripts/fetch-iana.js && node scripts/fetch-nginx.js && node scripts/fetch-node.js", "lint": "eslint --plugin markdown --ext js,md .", "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" } } statuses-1.5.0/scripts/000077500000000000000000000000001325657140000150625ustar00rootroot00000000000000statuses-1.5.0/scripts/build.js000066400000000000000000000011271325657140000165200ustar00rootroot00000000000000'use strict' var path = require('path') var write = require('./lib/write') // all codes var codes = {} // initialize with all IANA codes addData(codes, require('../src/iana.json')) // add the codes from node addData(codes, require('../src/node.json')) // add the codes from nginx addData(codes, require('../src/nginx.json')) // add the codes from apache addData(codes, require('../src/apache.json')) // write the JSON object write(path.join(__dirname, '../codes.json'), codes) function addData (db, obj) { Object.keys(obj).forEach(function (key) { db[key] = db[key] || obj[key] }) } statuses-1.5.0/scripts/fetch-apache.js000066400000000000000000000012021325657140000177230ustar00rootroot00000000000000'use strict' var getBody = require('raw-body') var https = require('https') var path = require('path') var write = require('./lib/write') var URL = 'https://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/http/http_protocol.c' https.get(URL, function onResponse (res) { getBody(res, true, function (err, body) { if (err) throw err var block = /status_lines\[[^\]]*\]\s*=\s*{([^}]+)};/m.exec(body)[1] var codes = {} var match var regexp = /"([0-9]+) ([^"]+)"/g while ((match = regexp.exec(block))) { codes[match[1]] = match[2] } write(path.join(__dirname, '../src/apache.json'), codes) }) }) statuses-1.5.0/scripts/fetch-iana.js000066400000000000000000000021001325657140000174100ustar00rootroot00000000000000'use strict' var https = require('https') var parser = require('csv-parse') var path = require('path') var toArray = require('stream-to-array') var write = require('./lib/write') var URL = 'https://www.iana.org/assignments/http-status-codes/http-status-codes-1.csv' https.get(URL, function onResponse (res) { toArray(res.pipe(parser()), function (err, rows) { if (err) throw err var codes = {} var headers = rows.shift().map(normalizeHeader) var reduceRows = generateRowMapper(headers) rows.forEach(function (row) { var obj = row.reduce(reduceRows, {}) if (obj.description !== 'Unassigned') { codes[obj.value] = obj.description } }) write(path.join(__dirname, '../src/iana.json'), codes) }) }) function generateRowMapper (headers) { return function reduceRows (obj, val, index) { if (val !== '') { obj[headers[index]] = val } return obj } } function normalizeHeader (val) { return val.substr(0, 1).toLowerCase() + val.substr(1).replace(/ (.)/, function (s, c) { return c.toUpperCase() }) } statuses-1.5.0/scripts/fetch-nginx.js000066400000000000000000000012221325657140000176270ustar00rootroot00000000000000'use strict' var getBody = require('raw-body') var https = require('https') var path = require('path') var write = require('./lib/write') var URL = 'https://hg.nginx.org/nginx/raw-file/default/src/http/ngx_http_header_filter_module.c' https.get(URL, function onResponse (res) { getBody(res, true, function (err, body) { if (err) throw err var block = /ngx_http_status_lines\[] = {([^}]+)};/m.exec(body)[1] var codes = {} var match var regexp = /ngx_string\("([0-9]+) ([^"]+)"\)/g while ((match = regexp.exec(block))) { codes[match[1]] = match[2] } write(path.join(__dirname, '../src/nginx.json'), codes) }) }) statuses-1.5.0/scripts/fetch-node.js000066400000000000000000000012261325657140000174350ustar00rootroot00000000000000'use strict' var getBody = require('raw-body') var https = require('https') var path = require('path') var write = require('./lib/write') var URL = 'https://raw.githubusercontent.com/nodejs/node/master/lib/_http_server.js' https.get(URL, function onResponse (res) { getBody(res, true, function (err, body) { if (err) throw err var block = /STATUS_CODES\s*=\s*{([^}]+)};/m.exec(body)[1] var codes = {} var match var regexp = /([0-9]+): '([^\\']*(?:\\'[^\\']*)*)'/g while ((match = regexp.exec(block))) { codes[match[1]] = match[2].replace(/\\'/g, "'") } write(path.join(__dirname, '../src/node.json'), codes) }) }) statuses-1.5.0/scripts/lib/000077500000000000000000000000001325657140000156305ustar00rootroot00000000000000statuses-1.5.0/scripts/lib/write.js000066400000000000000000000010211325657140000173120ustar00rootroot00000000000000'use strict' var fs = require('fs') module.exports = function write (path, obj) { var fd = fs.openSync(path, 'w') var keys = Object.keys(obj).sort() fs.writeSync(fd, '{\n') keys.forEach(function (key, i, arr) { fs.writeSync(fd, ' ' + JSON.stringify(key) + ': ' + JSON.stringify(obj[key]) + endLine.apply(this, arguments)) }) fs.writeSync(fd, '}\n') fs.closeSync(fd) } function endLine (val, index, array) { var comma = index + 1 === array.length ? '' : ',' return comma + '\n' } statuses-1.5.0/src/000077500000000000000000000000001325657140000141625ustar00rootroot00000000000000statuses-1.5.0/src/apache.json000066400000000000000000000033031325657140000162750ustar00rootroot00000000000000{ "100": "Continue", "101": "Switching Protocols", "102": "Processing", "200": "OK", "201": "Created", "202": "Accepted", "203": "Non-Authoritative Information", "204": "No Content", "205": "Reset Content", "206": "Partial Content", "207": "Multi-Status", "208": "Already Reported", "226": "IM Used", "300": "Multiple Choices", "301": "Moved Permanently", "302": "Found", "303": "See Other", "304": "Not Modified", "305": "Use Proxy", "307": "Temporary Redirect", "308": "Permanent Redirect", "400": "Bad Request", "401": "Unauthorized", "402": "Payment Required", "403": "Forbidden", "404": "Not Found", "405": "Method Not Allowed", "406": "Not Acceptable", "407": "Proxy Authentication Required", "408": "Request Timeout", "409": "Conflict", "410": "Gone", "411": "Length Required", "412": "Precondition Failed", "413": "Request Entity Too Large", "414": "Request-URI Too Long", "415": "Unsupported Media Type", "416": "Requested Range Not Satisfiable", "417": "Expectation Failed", "418": "I'm A Teapot", "421": "Misdirected Request", "422": "Unprocessable Entity", "423": "Locked", "424": "Failed Dependency", "426": "Upgrade Required", "428": "Precondition Required", "429": "Too Many Requests", "431": "Request Header Fields Too Large", "451": "Unavailable For Legal Reasons", "500": "Internal Server Error", "501": "Not Implemented", "502": "Bad Gateway", "503": "Service Unavailable", "504": "Gateway Timeout", "505": "HTTP Version Not Supported", "506": "Variant Also Negotiates", "507": "Insufficient Storage", "508": "Loop Detected", "510": "Not Extended", "511": "Network Authentication Required" } statuses-1.5.0/src/iana.json000066400000000000000000000032761325657140000157750ustar00rootroot00000000000000{ "100": "Continue", "101": "Switching Protocols", "102": "Processing", "103": "Early Hints", "200": "OK", "201": "Created", "202": "Accepted", "203": "Non-Authoritative Information", "204": "No Content", "205": "Reset Content", "206": "Partial Content", "207": "Multi-Status", "208": "Already Reported", "226": "IM Used", "300": "Multiple Choices", "301": "Moved Permanently", "302": "Found", "303": "See Other", "304": "Not Modified", "305": "Use Proxy", "306": "(Unused)", "307": "Temporary Redirect", "308": "Permanent Redirect", "400": "Bad Request", "401": "Unauthorized", "402": "Payment Required", "403": "Forbidden", "404": "Not Found", "405": "Method Not Allowed", "406": "Not Acceptable", "407": "Proxy Authentication Required", "408": "Request Timeout", "409": "Conflict", "410": "Gone", "411": "Length Required", "412": "Precondition Failed", "413": "Payload Too Large", "414": "URI Too Long", "415": "Unsupported Media Type", "416": "Range Not Satisfiable", "417": "Expectation Failed", "421": "Misdirected Request", "422": "Unprocessable Entity", "423": "Locked", "424": "Failed Dependency", "426": "Upgrade Required", "428": "Precondition Required", "429": "Too Many Requests", "431": "Request Header Fields Too Large", "451": "Unavailable For Legal Reasons", "500": "Internal Server Error", "501": "Not Implemented", "502": "Bad Gateway", "503": "Service Unavailable", "504": "Gateway Timeout", "505": "HTTP Version Not Supported", "506": "Variant Also Negotiates", "507": "Insufficient Storage", "508": "Loop Detected", "510": "Not Extended", "511": "Network Authentication Required" } statuses-1.5.0/src/nginx.json000066400000000000000000000017761325657140000162130ustar00rootroot00000000000000{ "200": "OK", "201": "Created", "202": "Accepted", "204": "No Content", "206": "Partial Content", "301": "Moved Permanently", "302": "Moved Temporarily", "303": "See Other", "304": "Not Modified", "307": "Temporary Redirect", "308": "Permanent Redirect", "400": "Bad Request", "401": "Unauthorized", "402": "Payment Required", "403": "Forbidden", "404": "Not Found", "405": "Not Allowed", "406": "Not Acceptable", "408": "Request Time-out", "409": "Conflict", "410": "Gone", "411": "Length Required", "412": "Precondition Failed", "413": "Request Entity Too Large", "414": "Request-URI Too Large", "415": "Unsupported Media Type", "416": "Requested Range Not Satisfiable", "421": "Misdirected Request", "429": "Too Many Requests", "500": "Internal Server Error", "501": "Not Implemented", "502": "Bad Gateway", "503": "Service Temporarily Unavailable", "504": "Gateway Time-out", "505": "HTTP Version Not Supported", "507": "Insufficient Storage" } statuses-1.5.0/src/node.json000066400000000000000000000034101325657140000160000ustar00rootroot00000000000000{ "100": "Continue", "101": "Switching Protocols", "102": "Processing", "103": "Early Hints", "200": "OK", "201": "Created", "202": "Accepted", "203": "Non-Authoritative Information", "204": "No Content", "205": "Reset Content", "206": "Partial Content", "207": "Multi-Status", "208": "Already Reported", "226": "IM Used", "300": "Multiple Choices", "301": "Moved Permanently", "302": "Found", "303": "See Other", "304": "Not Modified", "305": "Use Proxy", "307": "Temporary Redirect", "308": "Permanent Redirect", "400": "Bad Request", "401": "Unauthorized", "402": "Payment Required", "403": "Forbidden", "404": "Not Found", "405": "Method Not Allowed", "406": "Not Acceptable", "407": "Proxy Authentication Required", "408": "Request Timeout", "409": "Conflict", "410": "Gone", "411": "Length Required", "412": "Precondition Failed", "413": "Payload Too Large", "414": "URI Too Long", "415": "Unsupported Media Type", "416": "Range Not Satisfiable", "417": "Expectation Failed", "418": "I'm a teapot", "421": "Misdirected Request", "422": "Unprocessable Entity", "423": "Locked", "424": "Failed Dependency", "425": "Unordered Collection", "426": "Upgrade Required", "428": "Precondition Required", "429": "Too Many Requests", "431": "Request Header Fields Too Large", "451": "Unavailable For Legal Reasons", "500": "Internal Server Error", "501": "Not Implemented", "502": "Bad Gateway", "503": "Service Unavailable", "504": "Gateway Timeout", "505": "HTTP Version Not Supported", "506": "Variant Also Negotiates", "507": "Insufficient Storage", "508": "Loop Detected", "509": "Bandwidth Limit Exceeded", "510": "Not Extended", "511": "Network Authentication Required" } statuses-1.5.0/test/000077500000000000000000000000001325657140000143525ustar00rootroot00000000000000statuses-1.5.0/test/.eslintrc000066400000000000000000000000451325657140000161750ustar00rootroot00000000000000{ "env": { "mocha": true } } statuses-1.5.0/test/test.js000066400000000000000000000071201325657140000156670ustar00rootroot00000000000000 var assert = require('assert') var http = require('http') var status = require('..') describe('status', function () { describe('arguments', function () { describe('code', function () { it('should be required', function () { assert.throws(status, /code must be/) }) it('should accept a number', function () { assert.equal(status(200), 200) }) it('should accept a string', function () { assert.equal(status('OK'), 200) }) it('should accept a string number', function () { assert.equal(status('200'), 200) }) it('should reject an object', function () { assert.throws(status.bind(null, {}), /code must be/) }) }) }) describe('when given a number', function () { it('should be truthy when a valid status code', function () { assert.ok(status(200)) assert.ok(status(404)) assert.ok(status(500)) }) it('should throw for invalid status code', function () { assert.throws(status.bind(null, 0), /invalid status code/) assert.throws(status.bind(null, 1000), /invalid status code/) }) it('should throw for unknown status code', function () { assert.throws(status.bind(null, 299), /invalid status code/) assert.throws(status.bind(null, 310), /invalid status code/) }) }) describe('when given a string', function () { it('should be truthy when a valid status code', function () { assert.ok(status('200')) assert.ok(status('404')) assert.ok(status('500')) }) it('should be truthy when a valid status message', function () { assert.ok(status('OK')) assert.ok(status('Not Found')) assert.ok(status('Internal Server Error')) }) it('should be case insensitive', function () { assert.ok(status('Ok')) assert.ok(status('not found')) assert.ok(status('INTERNAL SERVER ERROR')) }) it('should throw for unknown status message', function () { assert.throws(status.bind(null, 'too many bugs'), /invalid status message/) }) it('should throw for unknown status code', function () { assert.throws(status.bind(null, '299'), /invalid status code/) }) }) describe('.STATUS_CODES', function () { it('should be a map of code to message', function () { assert.equal(status.STATUS_CODES[200], 'OK') }) it('should include codes from Node.js', function () { Object.keys(http.STATUS_CODES).forEach(function forEachCode (code) { assert.ok(status.STATUS_CODES[code], 'contains ' + code) }) }) }) describe('.codes', function () { it('should include codes from Node.js', function () { Object.keys(http.STATUS_CODES).forEach(function forEachCode (code) { assert.notEqual(status.codes.indexOf(Number(code)), -1, 'contains ' + code) }) }) }) describe('.empty', function () { it('should be an object', function () { assert.ok(status.empty) assert.equal(typeof status.empty, 'object') }) it('should include 204', function () { assert(status.empty[204]) }) }) describe('.redirect', function () { it('should be an object', function () { assert.ok(status.redirect) assert.equal(typeof status.redirect, 'object') }) it('should include 308', function () { assert(status.redirect[308]) }) }) describe('.retry', function () { it('should be an object', function () { assert.ok(status.retry) assert.equal(typeof status.retry, 'object') }) it('should include 504', function () { assert(status.retry[504]) }) }) })