New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

express-middleware

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-middleware - npm Package Compare versions

Comparing version

to
2.0.3

2

package.json
{
"name": "express-middleware",
"version": "2.0.2",
"version": "2.0.3",
"description": "Set of middlewares for Chauffeur-Privé",

@@ -5,0 +5,0 @@ "keywords": [

@@ -22,26 +22,2 @@ 'use strict';

/**
* Find matching language by exact match.
*
* To match, the language must have the same country code and region.
*
* @param {Array} languages Array of known languages.
* @param {Array} parsedLanguages Array of parsed languages from Accept-Language.
* @returns {String|null} The first matching language if found, null otherwise.
*/
function findExactLanguageMatch(languages, parsedLanguages) {
let matchingLanguage;
_.find(parsedLanguages,
lang => {
const languageString = languageObjectToString(lang);
if (!lang.region) {
matchingLanguage = findPartialLanguageMatch(languages, [lang]);
} else if (_.includes(languages, languageString)) {
matchingLanguage = languageString;
}
return matchingLanguage;
});
return matchingLanguage || null;
}
/**
* Find matching language by partial match.

@@ -101,5 +77,3 @@ *

const language = findExactLanguageMatch(languages, validParsedLanguages)
|| findPartialLanguageMatch(languages, validParsedLanguages)
|| languages[0];
const language = findPartialLanguageMatch(languages, validParsedLanguages) || languages[0];

@@ -106,0 +80,0 @@ req.language = language;

@@ -106,2 +106,14 @@ 'use strict';

it('should match the first language found with a partial matching', function test(done) {
const req = { get: () => 'en-FR;q=1.0, en-GB;q=0.9, fr-FR;q=0.8, vi-FR;q=0.7' };
const middleware = language({ languages });
expect(middleware).to.be.instanceof(Function);
middleware(req, null, () => {
expect(req.language).to.equal('en-US');
done();
});
});
it('should throw if languages is not set', function test() {

@@ -108,0 +120,0 @@ expect(() => language({ languages: null })).to.throw();