Socket
Socket
Sign inDemoInstall

negotiator

Package Overview
Dependencies
Maintainers
3
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.5.0 to 0.5.1

5

HISTORY.md

@@ -0,1 +1,6 @@

0.5.1 / 2015-02-14
==================
* Fix preference sorting to be stable for long acceptable lists
0.5.0 / 2014-12-18

@@ -2,0 +7,0 @@ ==================

21

lib/charset.js

@@ -45,9 +45,9 @@ module.exports = preferredCharsets;

function getCharsetPriority(charset, accepted) {
var priority = {i: -1, s: 0, q: 0};
function getCharsetPriority(charset, accepted, index) {
var priority = {o: -1, q: 0, s: 0};
for (var i = 0; i < accepted.length; i++) {
var spec = specify(charset, accepted[i]);
var spec = specify(charset, accepted[i], index);
if (spec && (priority.s - spec.s || priority.q - spec.q || priority.i - spec.i) < 0) {
if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) {
priority = spec;

@@ -60,3 +60,3 @@ }

function specify(charset, spec) {
function specify(charset, spec, index) {
var s = 0;

@@ -70,5 +70,6 @@ if(spec.charset.toLowerCase() === charset.toLowerCase()){

return {
s: s,
i: index,
o: spec.i,
q: spec.q,
i: spec.i
s: s
}

@@ -88,4 +89,4 @@ }

var priorities = provided.map(function getPriority(type) {
return getCharsetPriority(type, accepts);
var priorities = provided.map(function getPriority(type, index) {
return getCharsetPriority(type, accepts, index);
});

@@ -100,3 +101,3 @@

function compareSpecs(a, b) {
return (b.q - a.q) || (b.s - a.s) || (a.i - b.i) || 0;
return (b.q - a.q) || (b.s - a.s) || (a.o - b.o) || (a.i - b.i) || 0;
}

@@ -103,0 +104,0 @@

@@ -62,9 +62,9 @@ module.exports = preferredEncodings;

function getEncodingPriority(encoding, accepted) {
var priority = {i: -1, s: 0, q: 0};
function getEncodingPriority(encoding, accepted, index) {
var priority = {o: -1, q: 0, s: 0};
for (var i = 0; i < accepted.length; i++) {
var spec = specify(encoding, accepted[i]);
var spec = specify(encoding, accepted[i], index);
if (spec && (priority.s - spec.s || priority.q - spec.q || priority.i - spec.i) < 0) {
if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) {
priority = spec;

@@ -77,3 +77,3 @@ }

function specify(encoding, spec) {
function specify(encoding, spec, index) {
var s = 0;

@@ -87,5 +87,6 @@ if(spec.encoding.toLowerCase() === encoding.toLowerCase()){

return {
s: s,
i: index,
o: spec.i,
q: spec.q,
i: spec.i
s: s
}

@@ -104,4 +105,4 @@ };

var priorities = provided.map(function getPriority(type) {
return getEncodingPriority(type, accepts);
var priorities = provided.map(function getPriority(type, index) {
return getEncodingPriority(type, accepts, index);
});

@@ -116,3 +117,3 @@

function compareSpecs(a, b) {
return (b.q - a.q) || (b.s - a.s) || (a.i - b.i) || 0;
return (b.q - a.q) || (b.s - a.s) || (a.o - b.o) || (a.i - b.i) || 0;
}

@@ -119,0 +120,0 @@

@@ -49,9 +49,9 @@ module.exports = preferredLanguages;

function getLanguagePriority(language, accepted) {
var priority = {i: -1, s: 0, q: 0};
function getLanguagePriority(language, accepted, index) {
var priority = {o: -1, q: 0, s: 0};
for (var i = 0; i < accepted.length; i++) {
var spec = specify(language, accepted[i]);
var spec = specify(language, accepted[i], index);
if (spec && (priority.s - spec.s || priority.q - spec.q || priority.i - spec.i) < 0) {
if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) {
priority = spec;

@@ -64,3 +64,3 @@ }

function specify(language, spec) {
function specify(language, spec, index) {
var p = parseLanguage(language)

@@ -80,5 +80,6 @@ if (!p) return null;

return {
s: s,
i: index,
o: spec.i,
q: spec.q,
i: spec.i
s: s
}

@@ -98,4 +99,4 @@ };

var priorities = provided.map(function getPriority(type) {
return getLanguagePriority(type, accepts);
var priorities = provided.map(function getPriority(type, index) {
return getLanguagePriority(type, accepts, index);
});

@@ -110,3 +111,3 @@

function compareSpecs(a, b) {
return (b.q - a.q) || (b.s - a.s) || (a.i - b.i) || 0;
return (b.q - a.q) || (b.s - a.s) || (a.o - b.o) || (a.i - b.i) || 0;
}

@@ -113,0 +114,0 @@

@@ -55,9 +55,9 @@ module.exports = preferredMediaTypes;

function getMediaTypePriority(type, accepted) {
var priority = {i: -1, s: 0, q: 0};
function getMediaTypePriority(type, accepted, index) {
var priority = {o: -1, q: 0, s: 0};
for (var i = 0; i < accepted.length; i++) {
var spec = specify(type, accepted[i]);
var spec = specify(type, accepted[i], index);
if (spec && (priority.s - spec.s || priority.q - spec.q || priority.i - spec.i) < 0) {
if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) {
priority = spec;

@@ -70,3 +70,3 @@ }

function specify(type, spec) {
function specify(type, spec, index) {
var p = parseMediaType(type);

@@ -103,4 +103,5 @@ var s = 0;

return {
i: index,
o: spec.i,
q: spec.q,
i: spec.i,
s: s,

@@ -122,4 +123,4 @@ }

var priorities = provided.map(function getPriority(type) {
return getMediaTypePriority(type, accepts);
var priorities = provided.map(function getPriority(type, index) {
return getMediaTypePriority(type, accepts, index);
});

@@ -134,3 +135,3 @@

function compareSpecs(a, b) {
return (b.q - a.q) || (b.s - a.s) || (a.i - b.i) || 0;
return (b.q - a.q) || (b.s - a.s) || (a.o - b.o) || (a.i - b.i) || 0;
}

@@ -137,0 +138,0 @@

{
"name": "negotiator",
"description": "HTTP content negotiation",
"version": "0.5.0",
"version": "0.5.1",
"contributors": [

@@ -22,3 +22,4 @@ "Douglas Christopher Wilson <doug@somethingdoug.com>",

"istanbul": "0.3.5",
"nodeunit": "0.9.0"
"nodeunit": "0.9.0",
"tap": "0.5.0"
},

@@ -25,0 +26,0 @@ "files": [

@@ -47,10 +47,19 @@ # negotiator

##### mediaTypes(availableMediaTypes):
##### mediaType()
Returns an array of preferred media types ordered by priority from a list of available media types.
Returns the most preferred media type from the client.
##### mediaType(availableMediaType):
##### mediaType(availableMediaType)
Returns the top preferred media type from a list of available media types.
Returns the most preferred media type from a list of available media types.
##### mediaTypes()
Returns an array of preferred media types ordered by the client preference.
##### mediaTypes(availableMediaTypes)
Returns an array of preferred media types ordered by priority from a list of
available media types.
### Accept-Language Negotiation

@@ -79,10 +88,19 @@

##### languages(availableLanguages):
##### language()
Returns an array of preferred languages ordered by priority from a list of available languages.
Returns the most preferred language from the client.
##### language(availableLanguages):
##### language(availableLanguages)
Returns the top preferred language from a list of available languages.
Returns the most preferred language from a list of available languages.
##### languages()
Returns an array of preferred languages ordered by the client preference.
##### languages(availableLanguages)
Returns an array of preferred languages ordered by priority from a list of
available languages.
### Accept-Charset Negotiation

@@ -111,10 +129,19 @@

##### charsets(availableCharsets):
##### charset()
Returns an array of preferred charsets ordered by priority from a list of available charsets.
Returns the most preferred charset from the client.
##### charset(availableCharsets):
##### charset(availableCharsets)
Returns the top preferred charset from a list of available charsets.
Returns the most preferred charset from a list of available charsets.
##### charsets()
Returns an array of preferred charsets ordered by the client preference.
##### charsets(availableCharsets)
Returns an array of preferred charsets ordered by priority from a list of
available charsets.
### Accept-Encoding Negotiation

@@ -143,10 +170,25 @@

##### encodings(availableEncodings):
##### encoding()
Returns an array of preferred encodings ordered by priority from a list of available encodings.
Returns the most preferred encoding from the client.
##### encoding(availableEncodings):
##### encoding(availableEncodings)
Returns the top preferred encoding from a list of available encodings.
Returns the most preferred encoding from a list of available encodings.
##### encodings()
Returns an array of preferred encodings ordered by the client preference.
##### encodings(availableEncodings)
Returns an array of preferred encodings ordered by priority from a list of
available encodings.
## See Also
The [accepts](https://npmjs.org/package/accepts#readme) module builds on
this module and provides an alternative interface, mime type validation,
and more.
## License

@@ -156,11 +198,11 @@

[npm-image]: https://img.shields.io/npm/v/negotiator.svg?style=flat
[npm-image]: https://img.shields.io/npm/v/negotiator.svg
[npm-url]: https://npmjs.org/package/negotiator
[node-version-image]: https://img.shields.io/node/v/negotiator.svg?style=flat
[node-version-image]: https://img.shields.io/node/v/negotiator.svg
[node-version-url]: http://nodejs.org/download/
[travis-image]: https://img.shields.io/travis/jshttp/negotiator.svg?style=flat
[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.svg?style=flat
[coveralls-image]: https://img.shields.io/coveralls/jshttp/negotiator/master.svg
[coveralls-url]: https://coveralls.io/r/jshttp/negotiator?branch=master
[downloads-image]: https://img.shields.io/npm/dm/negotiator.svg?style=flat
[downloads-image]: https://img.shields.io/npm/dm/negotiator.svg
[downloads-url]: https://npmjs.org/package/negotiator
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