negotiator
Advanced tools
Comparing version 0.6.2 to 0.6.3
@@ -0,1 +1,6 @@ | ||
0.6.3 / 2022-01-22 | ||
================== | ||
* Revert "Lazy-load modules from main entry point" | ||
0.6.2 / 2019-04-29 | ||
@@ -2,0 +7,0 @@ ================== |
50
index.js
@@ -11,9 +11,7 @@ /*! | ||
/** | ||
* Cached loaded submodules. | ||
* @private | ||
*/ | ||
var preferredCharsets = require('./lib/charset') | ||
var preferredEncodings = require('./lib/encoding') | ||
var preferredLanguages = require('./lib/language') | ||
var preferredMediaTypes = require('./lib/mediaType') | ||
var modules = Object.create(null); | ||
/** | ||
@@ -47,3 +45,2 @@ * Module exports. | ||
Negotiator.prototype.charsets = function charsets(available) { | ||
var preferredCharsets = loadModule('charset').preferredCharsets; | ||
return preferredCharsets(this.request.headers['accept-charset'], available); | ||
@@ -58,3 +55,2 @@ }; | ||
Negotiator.prototype.encodings = function encodings(available) { | ||
var preferredEncodings = loadModule('encoding').preferredEncodings; | ||
return preferredEncodings(this.request.headers['accept-encoding'], available); | ||
@@ -69,3 +65,2 @@ }; | ||
Negotiator.prototype.languages = function languages(available) { | ||
var preferredLanguages = loadModule('language').preferredLanguages; | ||
return preferredLanguages(this.request.headers['accept-language'], available); | ||
@@ -80,3 +75,2 @@ }; | ||
Negotiator.prototype.mediaTypes = function mediaTypes(available) { | ||
var preferredMediaTypes = loadModule('mediaType').preferredMediaTypes; | ||
return preferredMediaTypes(this.request.headers.accept, available); | ||
@@ -94,37 +88,1 @@ }; | ||
Negotiator.prototype.preferredMediaTypes = Negotiator.prototype.mediaTypes; | ||
/** | ||
* Load the given module. | ||
* @private | ||
*/ | ||
function loadModule(moduleName) { | ||
var module = modules[moduleName]; | ||
if (module !== undefined) { | ||
return module; | ||
} | ||
// This uses a switch for static require analysis | ||
switch (moduleName) { | ||
case 'charset': | ||
module = require('./lib/charset'); | ||
break; | ||
case 'encoding': | ||
module = require('./lib/encoding'); | ||
break; | ||
case 'language': | ||
module = require('./lib/language'); | ||
break; | ||
case 'mediaType': | ||
module = require('./lib/mediaType'); | ||
break; | ||
default: | ||
throw new Error('Cannot find module \'' + moduleName + '\''); | ||
} | ||
// Store to prevent invoking require() | ||
modules[moduleName] = module; | ||
return module; | ||
} |
@@ -57,5 +57,5 @@ /** | ||
var prefix = match[1], | ||
suffix = match[2], | ||
full = prefix; | ||
var prefix = match[1] | ||
var suffix = match[2] | ||
var full = prefix | ||
@@ -62,0 +62,0 @@ if (suffix) full += "-" + suffix; |
{ | ||
"name": "negotiator", | ||
"description": "HTTP content negotiation", | ||
"version": "0.6.2", | ||
"version": "0.6.3", | ||
"contributors": [ | ||
@@ -21,6 +21,6 @@ "Douglas Christopher Wilson <doug@somethingdoug.com>", | ||
"devDependencies": { | ||
"eslint": "5.16.0", | ||
"eslint-plugin-markdown": "1.0.0", | ||
"mocha": "6.1.4", | ||
"nyc": "14.0.0" | ||
"eslint": "7.32.0", | ||
"eslint-plugin-markdown": "2.2.1", | ||
"mocha": "9.1.3", | ||
"nyc": "15.1.0" | ||
}, | ||
@@ -38,7 +38,7 @@ "files": [ | ||
"scripts": { | ||
"lint": "eslint --plugin markdown --ext js,md .", | ||
"lint": "eslint .", | ||
"test": "mocha --reporter spec --check-leaks --bail test/", | ||
"test-cov": "nyc --reporter=html --reporter=text npm test", | ||
"test-travis": "nyc --reporter=text npm test" | ||
"test-ci": "nyc --reporter=lcov --reporter=text npm test", | ||
"test-cov": "nyc --reporter=html --reporter=text npm test" | ||
} | ||
} |
@@ -6,3 +6,3 @@ # negotiator | ||
[![Node.js Version][node-version-image]][node-version-url] | ||
[![Build Status][travis-image]][travis-url] | ||
[![Build Status][github-actions-ci-image]][github-actions-ci-url] | ||
[![Test Coverage][coveralls-image]][coveralls-url] | ||
@@ -199,4 +199,2 @@ | ||
[node-version-url]: https://nodejs.org/en/download/ | ||
[travis-image]: https://img.shields.io/travis/jshttp/negotiator/master.svg | ||
[travis-url]: https://travis-ci.org/jshttp/negotiator | ||
[coveralls-image]: https://img.shields.io/coveralls/jshttp/negotiator/master.svg | ||
@@ -206,1 +204,3 @@ [coveralls-url]: https://coveralls.io/r/jshttp/negotiator?branch=master | ||
[downloads-url]: https://npmjs.org/package/negotiator | ||
[github-actions-ci-image]: https://img.shields.io/github/workflow/status/jshttp/negotiator/ci/master?label=ci | ||
[github-actions-ci-url]: https://github.com/jshttp/negotiator/actions/workflows/ci.yml |
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
27375
725