Socket
Socket
Sign inDemoInstall

negotiator

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

negotiator - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

22

lib/charset.js

@@ -8,3 +8,3 @@ module.exports = preferredCharsets;

}).filter(function(e) {
return e && e.q > 0;
return e;
});

@@ -41,3 +41,3 @@ }

// revsort
return a.q === b.q ? 0 : a.q > b.q ? -1 : 1;
return a.s > b.s ? -1 : 1;
})[0] || {q:0}).q;

@@ -47,7 +47,15 @@ }

function specify(charset, spec) {
if (spec.charset === '*' || spec.charset === charset) {
return spec;
var s = 0;
if(spec.charset === charset){
s |= 1;
} else if (spec.charset !== '*' ) {
return null
}
};
return {
s: s,
q: spec.q,
}
}
function preferredCharsets(accept, provided) {

@@ -62,3 +70,3 @@ accept = parseAcceptCharset(accept || '');

// revsort
return a[1] === b[1] ? 0 : a[1] > b[1] ? -1 : 1;
return a[1] > b[1] ? -1 : 1;
}).map(function(pair) {

@@ -71,2 +79,4 @@ return pair[0];

return a.q < b.q ? 1 : -1;
}).filter(function(type) {
return type.q > 0;
}).map(function(type) {

@@ -73,0 +83,0 @@ return type.charset;

@@ -38,3 +38,3 @@ module.exports = preferredEncodings;

return acceptableEncodings.filter(function(e) {
return e && e.q > 0;
return e;
});

@@ -68,7 +68,9 @@ }

function getEncodingPriority(encoding, accepted) {
return (accepted.filter(function(a) {
return (accepted.map(function(a) {
return specify(encoding, a);
}).filter(function(a){
return a;
}).sort(function (a, b) {
// revsort
return a.q === b.q ? 0 : a.q > b.q ? -1 : 1;
return a.s > b.s ? -1 : 1;
})[0] || {q:0}).q;

@@ -78,7 +80,15 @@ }

function specify(encoding, spec) {
if (spec.encoding === '*' || spec.encoding === encoding) {
return spec;
var s = 0;
if(spec.encoding === encoding){
s |= 1;
} else if (spec.encoding !== '*' ) {
return null
}
}
return {
s: s,
q: spec.q,
}
};
function preferredEncodings(accept, provided) {

@@ -101,2 +111,4 @@ accept = parseAcceptEncoding(accept || '');

return a.q < b.q ? 1 : -1;
}).filter(function(type){
return type.q > 0;
}).map(function(type) {

@@ -103,0 +115,0 @@ return type.encoding;

@@ -8,3 +8,3 @@ module.exports = preferredLanguages;

}).filter(function(e) {
return e && e.q > 0;
return e;
});

@@ -41,30 +41,31 @@ }

function getLanguagePriority(language, accepted) {
var match = getClosestMatch(language, accepted);
return match ? match.q : 0;
return (accepted.map(function(a){
return specify(language, a);
}).filter(function(a){
return a;
}).sort(function(a, b){
// revsort
return a.s > b.s ? -1 : 1;
})[0] || {q:0}).q;
}
function getClosestMatch(language, accepted) {
var parsed = parseLanguage(language);
function specify(language, spec) {
var p = parseLanguage(language)
var s = 0;
if(spec.full === p.full){
s |= 4;
} else if (spec.prefix === p.full) {
s |= 2;
} else if (spec.full === p.prefix) {
s |= 1;
} else if (spec.full !== '*' ) {
return null
}
var matches = accepted.filter(function(a) {
return a.full === parsed.full;
});
if (matches.length) return matches[0];
return {
s: s,
q: spec.q,
}
};
matches = accepted.filter(function(a) {
return a.prefix === parsed.prefix && !a.suffix;
});
if (matches.length) return matches[0];
matches = accepted.filter(function(a) {
return a.prefix === parsed.prefix;
});
if (matches.length) return matches[0];
matches = accepted.filter(function(a) {
return a.prefix === '*';
});
return matches[0];
}
function preferredLanguages(accept, provided) {

@@ -90,2 +91,4 @@ accept = parseAcceptLanguage(accept || '');

return a.q < b.q ? 1 : -1;
}).filter(function(type) {
return type.q > 0;
}).map(function(type) {

@@ -92,0 +95,0 @@ return type.full;

@@ -8,3 +8,3 @@ module.exports = preferredMediaTypes;

}).filter(function(e) {
return e && e.q > 0;
return e;
});

@@ -51,27 +51,38 @@ };

// revsort
return a.q > b.q ? -1 : 1;
return a.s > b.s ? -1 : 1;
})[0] || {q:0}).q;
}
function specifies(spec, type) {
return spec === '*' || spec === type;
}
function specify(type, spec) {
var p = parseMediaType(type);
var s = 0;
if(spec.type == p.type) {
s |= 4
} else if(spec.type != '*') {
return null;
}
if(spec.subtype == p.subtype) {
s |= 2
} else if(spec.subtype != '*') {
return null;
}
if (spec.params) {
var keys = Object.keys(spec.params);
if (keys.some(function (k) {
return !specifies(spec.params[k], p.params[k]);
return spec.params[k] == '*' || spec.params[k] == p.params[k];
})) {
// some didn't specify.
return null;
} else {
s |= 1;
}
}
if (specifies(spec.type, p.type) &&
specifies(spec.subtype, p.subtype)) {
return spec;
return {
q: spec.q,
s: s,
}
}

@@ -97,2 +108,4 @@

return a.q < b.q ? 1 : -1;
}).filter(function(type) {
return type.q > 0;
}).map(function(type) {

@@ -99,0 +112,0 @@ return type.full;

{
"name": "negotiator",
"description": "HTTP content negotiation",
"version": "0.4.0",
"version": "0.4.1",
"author": "Federico Romero <federico.romero@outboxlabs.com>",

@@ -6,0 +6,0 @@ "contributors": ["Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)"],

@@ -54,2 +54,6 @@ (function() {

selected: ['ISO-8859-1', 'utf-8']
}, {
accept: '*, utf-8;q=0',
provided: ['utf-8', 'ISO-8859-1'],
selected: ['ISO-8859-1']
}

@@ -56,0 +60,0 @@ ];

@@ -69,2 +69,6 @@ (function() {

}, {
accept: '*, compress;q=0',
provided: ['gzip', 'compress'],
selected: ['gzip']
}, {
accept: 'gzip;q=0.8, compress',

@@ -71,0 +75,0 @@ provided: null,

@@ -59,2 +59,6 @@ (function() {

}, {
accept: '*, en;q=0',
provided: ['en', 'es'],
selected: ['es']
}, {
accept: 'en-US;q=0.8, es',

@@ -61,0 +65,0 @@ provided: null,

@@ -62,2 +62,10 @@ (function() {

selected: ['text/html', 'application/json']
}, {
accept: 'text/*, text/html;q=0',
provided: ['text/html', 'text/plain'],
selected: ['text/plain']
}, {
accept: 'text/*, text/html;q=0.5',
provided: ['text/html', 'text/plain'],
selected: ['text/plain', 'text/html']
}

@@ -64,0 +72,0 @@ ];

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