Socket
Socket
Sign inDemoInstall

express-negotiator

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-negotiator - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

.travis.yml

21

lib/expressNegotiator.js

@@ -11,4 +11,16 @@ var fs = require('fs'),

// List taken from an older version of CLDR, so it's probably incomplete:
isLocaleIdRegExp = /^(?:aa|af|ak|am|ar|as|asa|az|be|bem|bez|bg|bm|bn|bo|br|brx|bs|byn|ca|cch|cgg|chr|cs|cy|da|dav|de|dv|dz|ebu|ee|el|en|eo|es|et|eu|fa|ff|fi|fil|fo|fr|fur|ga|gaa|gez|gl|gsw|gu|guz|gv|ha|haw|he|hi|hr|hu|hy|ia|id|ig|ii|in|is|it|iu|iw|ja|jmc|ka|kab|kaj|kam|kcg|kde|kea|kfo|khq|ki|kk|kl|kln|km|kn|ko|kok|kpe|ksb|ksh|ku|kw|ky|lag|lg|ln|lo|lt|luo|luy|lv|mas|mer|mfe|mg|mi|mk|ml|mn|mo|mr|ms|mt|my|naq|nb|nd|nds|ne|nl|nn|no|nr|nso|ny|nyn|oc|om|or|pa|pl|ps|pt|rm|ro|rof|root|ru|rw|rwk|sa|saq|se|seh|ses|sg|sh|shi|si|sid|sk|sl|sn|so|sq|sr|ss|ssy|st|sv|sw|syr|ta|te|teo|tg|th|ti|tig|tl|tn|to|tr|trv|ts|tt|tzm|ug|uk|ur|uz|ve|vi|vun|wal|wo|xh|xog|yo|zh|zu)(?:_|$)/;
isLocaleIdRegExp = /^(?:aa|af|ak|am|ar|as|asa|az|be|bem|bez|bg|bm|bn|bo|br|brx|bs|byn|ca|cch|cgg|chr|cs|cy|da|dav|de|dv|dz|ebu|ee|el|en|eo|es|et|eu|fa|ff|fi|fil|fo|fr|fur|ga|gaa|gez|gl|gsw|gu|guz|gv|ha|haw|he|hi|hr|hu|hy|ia|id|ig|ii|in|is|it|iu|iw|ja|jmc|ka|kab|kaj|kam|kcg|kde|kea|kfo|khq|ki|kk|kl|kln|km|kn|ko|kok|kpe|ksb|ksh|ku|kw|ky|lag|lg|ln|lo|lt|luo|luy|lv|mas|mer|mfe|mg|mi|mk|ml|mn|mo|mr|ms|mt|my|naq|nb|nd|nds|ne|nl|nn|no|nr|nso|ny|nyn|oc|om|or|pa|pl|ps|pt|rm|ro|rof|root|ru|rw|rwk|sa|saq|se|seh|ses|sg|sh|shi|si|sid|sk|sl|sn|so|sq|sr|ss|ssy|st|sv|sw|syr|ta|te|teo|tg|th|ti|tig|tl|tn|to|tr|trv|ts|tt|tzm|ug|uk|ur|uz|ve|vi|vun|wal|wo|xh|xog|yo|zh|zu)(?:_|$)/,
aliasesByLocaleId = {
no: ['nb'],
nb: ['no']
};
function localeIdsEqual(localeId1, localeId2) {
return (
localeId1 === localeId2 ||
(aliasesByLocaleId[localeId1] && aliasesByLocaleId[localeId1].indexOf(localeId2) !== -1) ||
(aliasesByLocaleId[localeId2] && aliasesByLocaleId[localeId2].indexOf(localeId1) !== -1)
);
}
// Note: These obscure extensions are listed in require('mime').types AND are considered valid locale ids: nb, so, ps, kfo, rm, st, sh, sid, in, tr, ms, gv, ts

@@ -237,3 +249,3 @@ // When resolving the variants we interpret them as locale ids.

} else if (variantInfo.allExtensionsMatched) {
if (!variantInfo.localeId || variantInfo.localeId === localeId) {
if (!variantInfo.localeId || localeIdsEqual(variantInfo.localeId, localeId)) {
var contentTypeQuality = 0;

@@ -277,6 +289,9 @@ if (variantInfo.contentType) {

}
// In case two acceptable entries have the same quality, prefer the text/html one.
if (contentTypeQuality > 0 &&
(!bestVariantInfo || contentTypeQuality > bestVariantQuality) ||
(contentTypeQuality === bestVariantQuality && bestVariantInfo.contentType !== 'text/html' && variantInfo.contentType === 'text/html')) {
(contentTypeQuality === bestVariantQuality && bestVariantInfo.contentType !== 'text/html' && variantInfo.contentType === 'text/html') ||
// Make sure that a strict locale id match takes precedence over an alias (in case eg. both nb and no versions are available):
bestVariantInfo && bestVariantInfo.localeId !== localeId && variantInfo.localeId === localeId) {

@@ -283,0 +298,0 @@ bestVariantInfo = variantInfo;

88

package.json
{
"name": "express-negotiator",
"description": "Express/connect middleware that does HTTP content negotiation for static files",
"author": "Andreas Lind Petersen <andreas@one.com>",
"keywords": [
"http",
"content negotiation",
"connect",
"accept",
"accept-language",
"cookie",
"express",
"localization",
"l10n",
"internationalization",
"i18n",
"locale",
"content-type",
"content type",
"html",
"static",
"extension",
"mime"
],
"version": "0.4.1",
"engines": {
"node": "*"
},
"dependencies": {
"async": "=0.2.8",
"mario": "=1.4.1",
"memoizeasync": "=0.3.0",
"memoizesync": "=0.2.0",
"mime": "=1.2.7",
"passerror": "=0.0.1",
"underscore": "=1.3.3"
},
"devDependencies": {
"express": "=2.5.11",
"mocha": "=1.13.0",
"unexpected": "=1.0.1"
},
"main": "lib/expressNegotiator.js"
"name": "express-negotiator",
"description": "Express/connect middleware that does HTTP content negotiation for static files",
"author": "Andreas Lind Petersen <andreas@one.com>",
"keywords": [
"http",
"content negotiation",
"connect",
"accept",
"accept-language",
"cookie",
"express",
"localization",
"l10n",
"internationalization",
"i18n",
"locale",
"content-type",
"content type",
"html",
"static",
"extension",
"mime"
],
"version": "0.4.2",
"engines": {
"node": "*"
},
"dependencies": {
"async": "=0.2.8",
"mario": "=1.4.1",
"memoizeasync": "=0.3.0",
"memoizesync": "=0.2.0",
"mime": "=1.2.7",
"passerror": "=0.0.1",
"underscore": "=1.3.3"
},
"devDependencies": {
"express": "=2.5.11",
"mocha": "=1.13.0",
"unexpected": "=1.0.1"
},
"main": "lib/expressNegotiator.js",
"scripts": {
"test": "mocha -R spec",
"travis": "npm test"
}
}

@@ -83,2 +83,10 @@ var Path = require('path'),

// no and nb should be considered aliases:
createTest('Accept-Language: no with only nb and en versions available', {url: '/onlyNbAndEnAvailable', headers: {accept: '*/html', 'accept-language': 'no'}}, '/onlyNbAndEnAvailable.nb.html');
createTest('Accept-Language: nb with only no and en versions available', {url: '/onlyNoAndEnAvailable', headers: {accept: '*/html', 'accept-language': 'nb'}}, '/onlyNoAndEnAvailable.no.html');
createTest('Accept-Language: nb with only no, nb, and en versions available', {url: '/onlyNoAndNbAndEnAvailable', headers: {accept: '*/html', 'accept-language': 'nb'}}, '/onlyNoAndNbAndEnAvailable.nb.html');
createTest('Accept-Language: no with only no, nb, and en versions available', {url: '/onlyNoAndNbAndEnAvailable', headers: {accept: '*/html', 'accept-language': 'no'}}, '/onlyNoAndNbAndEnAvailable.no.html');
describe('with multiple roots', function () {

@@ -85,0 +93,0 @@ createTest(

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc