accept
Advanced tools
Comparing version 2.1.4 to 2.2.3
'use strict'; | ||
// Load modules | ||
const Hoek = require('hoek'); | ||
// Declare internals | ||
const internals = {}; | ||
@@ -142,3 +138,3 @@ | ||
return a.weight < b.weight; | ||
return b.weight - a.weight; | ||
}; | ||
@@ -145,0 +141,0 @@ |
'use strict'; | ||
// Load modules | ||
const Boom = require('boom'); | ||
@@ -9,4 +7,2 @@ const Hoek = require('hoek'); | ||
// Declare internals | ||
const internals = {}; | ||
@@ -149,3 +145,3 @@ | ||
return (a.score === b.score ? 0 : (a.score < b.score ? 1 : -1)); | ||
return b.score - a.score; | ||
}; |
'use strict'; | ||
// Load modules | ||
const Charset = require('./charset'); | ||
@@ -10,2 +8,3 @@ const Encoding = require('./encoding'); | ||
exports.charset = Charset.charset; | ||
@@ -12,0 +11,0 @@ exports.charsets = Charset.charsets; |
'use strict'; | ||
// Load modules | ||
const Hoek = require('hoek'); | ||
// Declare internals | ||
const internals = {}; | ||
@@ -16,3 +12,2 @@ | ||
exports.language = function (header, preferences) { | ||
@@ -104,3 +99,3 @@ | ||
return a.weight < b.weight; | ||
return b.weight - a.weight; | ||
}; | ||
@@ -107,0 +102,0 @@ |
'use strict'; | ||
// Declare internals | ||
const internals = {}; | ||
// Accept: audio/*; q=0.2, audio/basic | ||
@@ -29,7 +28,8 @@ // text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c | ||
internals.getParts = function (item) { | ||
internals.getParts = function (item, pos) { | ||
const result = { | ||
weight: 1, | ||
mediaType: '' | ||
mediaType: '', | ||
pos | ||
}; | ||
@@ -50,5 +50,7 @@ | ||
} | ||
return result; | ||
}; | ||
// 1: token 2: qvalue | ||
@@ -62,39 +64,51 @@ internals.partsRegex = /\s*(.+\/.+?)(?:\s*;\s*[qQ]\=([01](?:\.\d*)?))?\s*$/; | ||
internals.compareByWeightAndSpecificity = function (a, b) { | ||
if (a.weight !== b.weight) { | ||
return a.weight < b.weight; | ||
return b.weight - a.weight; | ||
} | ||
// We have the same weight, so now look for specificity | ||
const aSlashParts = a.mediaType.split('/'); | ||
const bSlashParts = b.mediaType.split('/'); | ||
if (aSlashParts[0] !== bSlashParts[0]) { | ||
// First part of items are different so no | ||
// further specificity is implied. | ||
// Don't change order. | ||
return 0; | ||
const byPos = a.pos - b.pos; | ||
const aParts = a.mediaType.split('/'); | ||
const bParts = b.mediaType.split('/'); | ||
if (aParts[0] !== bParts[0]) { // First part of items are different so no further specificity is implied | ||
return byPos; | ||
} | ||
if (aSlashParts[1] !== '*' && bSlashParts[1] === '*') { | ||
// Wildcard is less specific | ||
if (aParts[1] === '*' && | ||
bParts[1] !== '*') { | ||
return 1; | ||
} | ||
if (bParts[1] === '*' && | ||
aParts[1] !== '*') { | ||
return -1; | ||
} | ||
if (aSlashParts[1] === '*' && bSlashParts[1] !== '*') { | ||
return 1; | ||
// Look for items with extensions | ||
const aHasExtension = aParts[1].includes(';'); | ||
const bHasExtension = bParts[1].includes(';'); | ||
if (aHasExtension === bHasExtension) { | ||
return byPos; | ||
} | ||
// look for items with extensions | ||
const aHasExtension = aSlashParts[1].indexOf(';') !== -1; | ||
const bHasExtension = bSlashParts[1].indexOf(';') !== -1; | ||
if (aHasExtension) { | ||
return -1; | ||
} | ||
else if (bHasExtension) { | ||
return 1; | ||
} | ||
return 0; | ||
return 1; | ||
}; | ||
internals.partToMediaType = function (item) { | ||
@@ -105,2 +119,3 @@ | ||
internals.isNumber = function (n) { | ||
@@ -107,0 +122,0 @@ |
{ | ||
"name": "accept", | ||
"description": "HTTP Accept-* headers parsing", | ||
"version": "2.1.4", | ||
"version": "2.2.3", | ||
"repository": "git://github.com/hapijs/accept", | ||
"engines": { | ||
"node": ">=6.0.0" | ||
}, | ||
"main": "lib/index.js", | ||
@@ -13,5 +16,2 @@ "keywords": [ | ||
], | ||
"engines": { | ||
"node": ">=4.0.0" | ||
}, | ||
"dependencies": { | ||
@@ -23,11 +23,9 @@ "boom": "5.x.x", | ||
"code": "4.x.x", | ||
"lab": "13.x.x", | ||
"npmignore": "0.2.x" | ||
"lab": "14.x.x" | ||
}, | ||
"scripts": { | ||
"test": "lab -a code -t 100 -L", | ||
"test-cov-html": "lab -a code -r html -o coverage.html", | ||
"update-npmignore": "npmignore" | ||
"test": "lab -a code -t 100 -L -l", | ||
"test-cov-html": "lab -a code -r html -o coverage.html -l" | ||
}, | ||
"license": "BSD-3-Clause" | ||
"license": "SEE LICENSE IN LICENSE.md" | ||
} |
@@ -1,9 +0,11 @@ | ||
#Accept | ||
# accept | ||
HTTP Accept-* headers parsing. | ||
[![npm version](https://badge.fury.io/js/accept.svg)](http://badge.fury.io/js/accept) [![Build Status](https://secure.travis-ci.org/hapijs/accept.png)](http://travis-ci.org/hapijs/accept) [![Dependency Status](https://david-dm.org/hapijs/accept.svg)](https://david-dm.org/hapijs/accept) | ||
[![Build Status](https://travis-ci.org/hapijs/accept.svg?branch=v2-commercial)](https://travis-ci.org/hapijs/accept) | ||
Lead Maintainer - [Mark Bradshaw](https://github.com/mark-bradshaw) | ||
## License | ||
This version of the package requires a commercial license. You may not use, copy, or distribute it without first acquiring a commercial license from Sideway Inc. Using this software without a license is a violation of US and international law. To obtain a license, please contact [sales@sideway.com](mailto:sales@sideway.com). The open source version of this package can be found [here](https://github.com/hapijs/accept). | ||
## Introduction | ||
@@ -10,0 +12,0 @@ |
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
2
20
15331
2
80
385
1