Changements dans les modules (nouvelle version Express, mysql, ..)
This commit is contained in:
83
node_modules/negotiator/lib/charset.js
generated
vendored
83
node_modules/negotiator/lib/charset.js
generated
vendored
@@ -1,32 +1,5 @@
|
||||
/**
|
||||
* negotiator
|
||||
* Copyright(c) 2012 Isaac Z. Schlueter
|
||||
* Copyright(c) 2014 Federico Romero
|
||||
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
* @public
|
||||
*/
|
||||
|
||||
module.exports = preferredCharsets;
|
||||
module.exports.preferredCharsets = preferredCharsets;
|
||||
|
||||
/**
|
||||
* Module variables.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var simpleCharsetRegExp = /^\s*([^\s;]+)\s*(?:;(.*))?$/;
|
||||
|
||||
/**
|
||||
* Parse the Accept-Charset header.
|
||||
* @private
|
||||
*/
|
||||
preferredCharsets.preferredCharsets = preferredCharsets;
|
||||
|
||||
function parseAcceptCharset(accept) {
|
||||
var accepts = accept.split(',');
|
||||
@@ -45,21 +18,16 @@ function parseAcceptCharset(accept) {
|
||||
return accepts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a charset from the Accept-Charset header.
|
||||
* @private
|
||||
*/
|
||||
|
||||
function parseCharset(str, i) {
|
||||
var match = simpleCharsetRegExp.exec(str);
|
||||
function parseCharset(s, i) {
|
||||
var match = s.match(/^\s*(\S+?)\s*(?:;(.*))?$/);
|
||||
if (!match) return null;
|
||||
|
||||
var charset = match[1];
|
||||
var q = 1;
|
||||
if (match[2]) {
|
||||
var params = match[2].split(';')
|
||||
for (var j = 0; j < params.length; j++) {
|
||||
var p = params[j].trim().split('=');
|
||||
for (var i = 0; i < params.length; i ++) {
|
||||
var p = params[i].trim().split('=');
|
||||
if (p[0] === 'q') {
|
||||
q = parseFloat(p[1]);
|
||||
break;
|
||||
@@ -74,11 +42,6 @@ function parseCharset(str, i) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the priority of a charset.
|
||||
* @private
|
||||
*/
|
||||
|
||||
function getCharsetPriority(charset, accepted, index) {
|
||||
var priority = {o: -1, q: 0, s: 0};
|
||||
|
||||
@@ -93,11 +56,6 @@ function getCharsetPriority(charset, accepted, index) {
|
||||
return priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specificity of the charset.
|
||||
* @private
|
||||
*/
|
||||
|
||||
function specify(charset, spec, index) {
|
||||
var s = 0;
|
||||
if(spec.charset.toLowerCase() === charset.toLowerCase()){
|
||||
@@ -114,21 +72,15 @@ function specify(charset, spec, index) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the preferred charsets from an Accept-Charset header.
|
||||
* @public
|
||||
*/
|
||||
|
||||
function preferredCharsets(accept, provided) {
|
||||
// RFC 2616 sec 14.2: no header = *
|
||||
var accepts = parseAcceptCharset(accept === undefined ? '*' : accept || '');
|
||||
|
||||
if (!provided) {
|
||||
// sorted list of all charsets
|
||||
return accepts
|
||||
.filter(isQuality)
|
||||
.sort(compareSpecs)
|
||||
.map(getFullCharset);
|
||||
return accepts.filter(isQuality).sort(compareSpecs).map(function getCharset(spec) {
|
||||
return spec.charset;
|
||||
});
|
||||
}
|
||||
|
||||
var priorities = provided.map(function getPriority(type, index) {
|
||||
@@ -141,29 +93,10 @@ function preferredCharsets(accept, provided) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two specs.
|
||||
* @private
|
||||
*/
|
||||
|
||||
function compareSpecs(a, b) {
|
||||
return (b.q - a.q) || (b.s - a.s) || (a.o - b.o) || (a.i - b.i) || 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get full charset string.
|
||||
* @private
|
||||
*/
|
||||
|
||||
function getFullCharset(spec) {
|
||||
return spec.charset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a spec has any quality.
|
||||
* @private
|
||||
*/
|
||||
|
||||
function isQuality(spec) {
|
||||
return spec.q > 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user