format: prettify entire project
This commit is contained in:
229
node_modules/content-disposition/index.js
generated
vendored
229
node_modules/content-disposition/index.js
generated
vendored
@ -4,45 +4,45 @@
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
* @public
|
||||
*/
|
||||
|
||||
module.exports = contentDisposition
|
||||
module.exports.parse = parse
|
||||
module.exports = contentDisposition;
|
||||
module.exports.parse = parse;
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var basename = require('path').basename
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
var basename = require('path').basename;
|
||||
var Buffer = require('safe-buffer').Buffer;
|
||||
|
||||
/**
|
||||
* RegExp to match non attr-char, *after* encodeURIComponent (i.e. not including "%")
|
||||
* @private
|
||||
*/
|
||||
|
||||
var ENCODE_URL_ATTR_CHAR_REGEXP = /[\x00-\x20"'()*,/:;<=>?@[\\\]{}\x7f]/g // eslint-disable-line no-control-regex
|
||||
var ENCODE_URL_ATTR_CHAR_REGEXP = /[\x00-\x20"'()*,/:;<=>?@[\\\]{}\x7f]/g; // eslint-disable-line no-control-regex
|
||||
|
||||
/**
|
||||
* RegExp to match percent encoding escape.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var HEX_ESCAPE_REGEXP = /%[0-9A-Fa-f]{2}/
|
||||
var HEX_ESCAPE_REPLACE_REGEXP = /%([0-9A-Fa-f]{2})/g
|
||||
var HEX_ESCAPE_REGEXP = /%[0-9A-Fa-f]{2}/;
|
||||
var HEX_ESCAPE_REPLACE_REGEXP = /%([0-9A-Fa-f]{2})/g;
|
||||
|
||||
/**
|
||||
* RegExp to match non-latin1 characters.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var NON_LATIN1_REGEXP = /[^\x20-\x7e\xa0-\xff]/g
|
||||
var NON_LATIN1_REGEXP = /[^\x20-\x7e\xa0-\xff]/g;
|
||||
|
||||
/**
|
||||
* RegExp to match quoted-pair in RFC 2616
|
||||
@ -52,14 +52,14 @@ var NON_LATIN1_REGEXP = /[^\x20-\x7e\xa0-\xff]/g
|
||||
* @private
|
||||
*/
|
||||
|
||||
var QESC_REGEXP = /\\([\u0000-\u007f])/g // eslint-disable-line no-control-regex
|
||||
var QESC_REGEXP = /\\([\u0000-\u007f])/g; // eslint-disable-line no-control-regex
|
||||
|
||||
/**
|
||||
* RegExp to match chars that must be quoted-pair in RFC 2616
|
||||
* @private
|
||||
*/
|
||||
|
||||
var QUOTE_REGEXP = /([\\"])/g
|
||||
var QUOTE_REGEXP = /([\\"])/g;
|
||||
|
||||
/**
|
||||
* RegExp for various RFC 2616 grammar
|
||||
@ -86,9 +86,10 @@ var QUOTE_REGEXP = /([\\"])/g
|
||||
* @private
|
||||
*/
|
||||
|
||||
var PARAM_REGEXP = /;[\x09\x20]*([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*=[\x09\x20]*("(?:[\x20!\x23-\x5b\x5d-\x7e\x80-\xff]|\\[\x20-\x7e])*"|[!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*/g // eslint-disable-line no-control-regex
|
||||
var TEXT_REGEXP = /^[\x20-\x7e\x80-\xff]+$/
|
||||
var TOKEN_REGEXP = /^[!#$%&'*+.0-9A-Z^_`a-z|~-]+$/
|
||||
var PARAM_REGEXP =
|
||||
/;[\x09\x20]*([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*=[\x09\x20]*("(?:[\x20!\x23-\x5b\x5d-\x7e\x80-\xff]|\\[\x20-\x7e])*"|[!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*/g; // eslint-disable-line no-control-regex
|
||||
var TEXT_REGEXP = /^[\x20-\x7e\x80-\xff]+$/;
|
||||
var TOKEN_REGEXP = /^[!#$%&'*+.0-9A-Z^_`a-z|~-]+$/;
|
||||
|
||||
/**
|
||||
* RegExp for various RFC 5987 grammar
|
||||
@ -112,7 +113,8 @@ var TOKEN_REGEXP = /^[!#$%&'*+.0-9A-Z^_`a-z|~-]+$/
|
||||
* @private
|
||||
*/
|
||||
|
||||
var EXT_VALUE_REGEXP = /^([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[A-Za-z]{2,3}(?:-[A-Za-z]{3}){0,3}|[A-Za-z]{4,8}|)'((?:%[0-9A-Fa-f]{2}|[A-Za-z0-9!#$&+.^_`|~-])+)$/
|
||||
var EXT_VALUE_REGEXP =
|
||||
/^([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[A-Za-z]{2,3}(?:-[A-Za-z]{3}){0,3}|[A-Za-z]{4,8}|)'((?:%[0-9A-Fa-f]{2}|[A-Za-z0-9!#$&+.^_`|~-])+)$/;
|
||||
|
||||
/**
|
||||
* RegExp for various RFC 6266 grammar
|
||||
@ -128,7 +130,8 @@ var EXT_VALUE_REGEXP = /^([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[A-Za-z]{2,3}(?:-[A-Za-
|
||||
* @private
|
||||
*/
|
||||
|
||||
var DISPOSITION_TYPE_REGEXP = /^([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*(?:$|;)/ // eslint-disable-line no-control-regex
|
||||
var DISPOSITION_TYPE_REGEXP =
|
||||
/^([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*(?:$|;)/; // eslint-disable-line no-control-regex
|
||||
|
||||
/**
|
||||
* Create an attachment Content-Disposition header.
|
||||
@ -141,17 +144,17 @@ var DISPOSITION_TYPE_REGEXP = /^([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*(?:$|;)/
|
||||
* @public
|
||||
*/
|
||||
|
||||
function contentDisposition (filename, options) {
|
||||
var opts = options || {}
|
||||
function contentDisposition(filename, options) {
|
||||
var opts = options || {};
|
||||
|
||||
// get type
|
||||
var type = opts.type || 'attachment'
|
||||
var type = opts.type || 'attachment';
|
||||
|
||||
// get parameters
|
||||
var params = createparams(filename, opts.fallback)
|
||||
var params = createparams(filename, opts.fallback);
|
||||
|
||||
// format into string
|
||||
return format(new ContentDisposition(type, params))
|
||||
return format(new ContentDisposition(type, params));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,55 +166,54 @@ function contentDisposition (filename, options) {
|
||||
* @private
|
||||
*/
|
||||
|
||||
function createparams (filename, fallback) {
|
||||
function createparams(filename, fallback) {
|
||||
if (filename === undefined) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
var params = {}
|
||||
var params = {};
|
||||
|
||||
if (typeof filename !== 'string') {
|
||||
throw new TypeError('filename must be a string')
|
||||
throw new TypeError('filename must be a string');
|
||||
}
|
||||
|
||||
// fallback defaults to true
|
||||
if (fallback === undefined) {
|
||||
fallback = true
|
||||
fallback = true;
|
||||
}
|
||||
|
||||
if (typeof fallback !== 'string' && typeof fallback !== 'boolean') {
|
||||
throw new TypeError('fallback must be a string or boolean')
|
||||
throw new TypeError('fallback must be a string or boolean');
|
||||
}
|
||||
|
||||
if (typeof fallback === 'string' && NON_LATIN1_REGEXP.test(fallback)) {
|
||||
throw new TypeError('fallback must be ISO-8859-1 string')
|
||||
throw new TypeError('fallback must be ISO-8859-1 string');
|
||||
}
|
||||
|
||||
// restrict to file base name
|
||||
var name = basename(filename)
|
||||
var name = basename(filename);
|
||||
|
||||
// determine if name is suitable for quoted string
|
||||
var isQuotedString = TEXT_REGEXP.test(name)
|
||||
var isQuotedString = TEXT_REGEXP.test(name);
|
||||
|
||||
// generate fallback name
|
||||
var fallbackName = typeof fallback !== 'string'
|
||||
? fallback && getlatin1(name)
|
||||
: basename(fallback)
|
||||
var hasFallback = typeof fallbackName === 'string' && fallbackName !== name
|
||||
var fallbackName =
|
||||
typeof fallback !== 'string' ?
|
||||
fallback && getlatin1(name)
|
||||
: basename(fallback);
|
||||
var hasFallback = typeof fallbackName === 'string' && fallbackName !== name;
|
||||
|
||||
// set extended filename parameter
|
||||
if (hasFallback || !isQuotedString || HEX_ESCAPE_REGEXP.test(name)) {
|
||||
params['filename*'] = name
|
||||
params['filename*'] = name;
|
||||
}
|
||||
|
||||
// set filename parameter
|
||||
if (isQuotedString || hasFallback) {
|
||||
params.filename = hasFallback
|
||||
? fallbackName
|
||||
: name
|
||||
params.filename = hasFallback ? fallbackName : name;
|
||||
}
|
||||
|
||||
return params
|
||||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -224,34 +226,35 @@ function createparams (filename, fallback) {
|
||||
* @private
|
||||
*/
|
||||
|
||||
function format (obj) {
|
||||
var parameters = obj.parameters
|
||||
var type = obj.type
|
||||
function format(obj) {
|
||||
var parameters = obj.parameters;
|
||||
var type = obj.type;
|
||||
|
||||
if (!type || typeof type !== 'string' || !TOKEN_REGEXP.test(type)) {
|
||||
throw new TypeError('invalid type')
|
||||
throw new TypeError('invalid type');
|
||||
}
|
||||
|
||||
// start with normalized type
|
||||
var string = String(type).toLowerCase()
|
||||
var string = String(type).toLowerCase();
|
||||
|
||||
// append parameters
|
||||
if (parameters && typeof parameters === 'object') {
|
||||
var param
|
||||
var params = Object.keys(parameters).sort()
|
||||
var param;
|
||||
var params = Object.keys(parameters).sort();
|
||||
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
param = params[i]
|
||||
param = params[i];
|
||||
|
||||
var val = param.substr(-1) === '*'
|
||||
? ustring(parameters[param])
|
||||
: qstring(parameters[param])
|
||||
var val =
|
||||
param.substr(-1) === '*' ?
|
||||
ustring(parameters[param])
|
||||
: qstring(parameters[param]);
|
||||
|
||||
string += '; ' + param + '=' + val
|
||||
string += '; ' + param + '=' + val;
|
||||
}
|
||||
}
|
||||
|
||||
return string
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -262,32 +265,32 @@ function format (obj) {
|
||||
* @private
|
||||
*/
|
||||
|
||||
function decodefield (str) {
|
||||
var match = EXT_VALUE_REGEXP.exec(str)
|
||||
function decodefield(str) {
|
||||
var match = EXT_VALUE_REGEXP.exec(str);
|
||||
|
||||
if (!match) {
|
||||
throw new TypeError('invalid extended field value')
|
||||
throw new TypeError('invalid extended field value');
|
||||
}
|
||||
|
||||
var charset = match[1].toLowerCase()
|
||||
var encoded = match[2]
|
||||
var value
|
||||
var charset = match[1].toLowerCase();
|
||||
var encoded = match[2];
|
||||
var value;
|
||||
|
||||
// to binary string
|
||||
var binary = encoded.replace(HEX_ESCAPE_REPLACE_REGEXP, pdecode)
|
||||
var binary = encoded.replace(HEX_ESCAPE_REPLACE_REGEXP, pdecode);
|
||||
|
||||
switch (charset) {
|
||||
case 'iso-8859-1':
|
||||
value = getlatin1(binary)
|
||||
break
|
||||
value = getlatin1(binary);
|
||||
break;
|
||||
case 'utf-8':
|
||||
value = Buffer.from(binary, 'binary').toString('utf8')
|
||||
break
|
||||
value = Buffer.from(binary, 'binary').toString('utf8');
|
||||
break;
|
||||
default:
|
||||
throw new TypeError('unsupported charset in extended field')
|
||||
throw new TypeError('unsupported charset in extended field');
|
||||
}
|
||||
|
||||
return value
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -298,9 +301,9 @@ function decodefield (str) {
|
||||
* @private
|
||||
*/
|
||||
|
||||
function getlatin1 (val) {
|
||||
function getlatin1(val) {
|
||||
// simple Unicode -> ISO-8859-1 transformation
|
||||
return String(val).replace(NON_LATIN1_REGEXP, '?')
|
||||
return String(val).replace(NON_LATIN1_REGEXP, '?');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -311,76 +314,73 @@ function getlatin1 (val) {
|
||||
* @public
|
||||
*/
|
||||
|
||||
function parse (string) {
|
||||
function parse(string) {
|
||||
if (!string || typeof string !== 'string') {
|
||||
throw new TypeError('argument string is required')
|
||||
throw new TypeError('argument string is required');
|
||||
}
|
||||
|
||||
var match = DISPOSITION_TYPE_REGEXP.exec(string)
|
||||
var match = DISPOSITION_TYPE_REGEXP.exec(string);
|
||||
|
||||
if (!match) {
|
||||
throw new TypeError('invalid type format')
|
||||
throw new TypeError('invalid type format');
|
||||
}
|
||||
|
||||
// normalize type
|
||||
var index = match[0].length
|
||||
var type = match[1].toLowerCase()
|
||||
var index = match[0].length;
|
||||
var type = match[1].toLowerCase();
|
||||
|
||||
var key
|
||||
var names = []
|
||||
var params = {}
|
||||
var value
|
||||
var key;
|
||||
var names = [];
|
||||
var params = {};
|
||||
var value;
|
||||
|
||||
// calculate index to start at
|
||||
index = PARAM_REGEXP.lastIndex = match[0].substr(-1) === ';'
|
||||
? index - 1
|
||||
: index
|
||||
index = PARAM_REGEXP.lastIndex =
|
||||
match[0].substr(-1) === ';' ? index - 1 : index;
|
||||
|
||||
// match parameters
|
||||
while ((match = PARAM_REGEXP.exec(string))) {
|
||||
if (match.index !== index) {
|
||||
throw new TypeError('invalid parameter format')
|
||||
throw new TypeError('invalid parameter format');
|
||||
}
|
||||
|
||||
index += match[0].length
|
||||
key = match[1].toLowerCase()
|
||||
value = match[2]
|
||||
index += match[0].length;
|
||||
key = match[1].toLowerCase();
|
||||
value = match[2];
|
||||
|
||||
if (names.indexOf(key) !== -1) {
|
||||
throw new TypeError('invalid duplicate parameter')
|
||||
throw new TypeError('invalid duplicate parameter');
|
||||
}
|
||||
|
||||
names.push(key)
|
||||
names.push(key);
|
||||
|
||||
if (key.indexOf('*') + 1 === key.length) {
|
||||
// decode extended value
|
||||
key = key.slice(0, -1)
|
||||
value = decodefield(value)
|
||||
key = key.slice(0, -1);
|
||||
value = decodefield(value);
|
||||
|
||||
// overwrite existing value
|
||||
params[key] = value
|
||||
continue
|
||||
params[key] = value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof params[key] === 'string') {
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value[0] === '"') {
|
||||
// remove quotes and escapes
|
||||
value = value
|
||||
.substr(1, value.length - 2)
|
||||
.replace(QESC_REGEXP, '$1')
|
||||
value = value.substr(1, value.length - 2).replace(QESC_REGEXP, '$1');
|
||||
}
|
||||
|
||||
params[key] = value
|
||||
params[key] = value;
|
||||
}
|
||||
|
||||
if (index !== -1 && index !== string.length) {
|
||||
throw new TypeError('invalid parameter format')
|
||||
throw new TypeError('invalid parameter format');
|
||||
}
|
||||
|
||||
return new ContentDisposition(type, params)
|
||||
return new ContentDisposition(type, params);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -392,8 +392,8 @@ function parse (string) {
|
||||
* @private
|
||||
*/
|
||||
|
||||
function pdecode (str, hex) {
|
||||
return String.fromCharCode(parseInt(hex, 16))
|
||||
function pdecode(str, hex) {
|
||||
return String.fromCharCode(parseInt(hex, 16));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -404,11 +404,8 @@ function pdecode (str, hex) {
|
||||
* @private
|
||||
*/
|
||||
|
||||
function pencode (char) {
|
||||
return '%' + String(char)
|
||||
.charCodeAt(0)
|
||||
.toString(16)
|
||||
.toUpperCase()
|
||||
function pencode(char) {
|
||||
return '%' + String(char).charCodeAt(0).toString(16).toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -419,10 +416,10 @@ function pencode (char) {
|
||||
* @private
|
||||
*/
|
||||
|
||||
function qstring (val) {
|
||||
var str = String(val)
|
||||
function qstring(val) {
|
||||
var str = String(val);
|
||||
|
||||
return '"' + str.replace(QUOTE_REGEXP, '\\$1') + '"'
|
||||
return '"' + str.replace(QUOTE_REGEXP, '\\$1') + '"';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -433,14 +430,16 @@ function qstring (val) {
|
||||
* @private
|
||||
*/
|
||||
|
||||
function ustring (val) {
|
||||
var str = String(val)
|
||||
function ustring(val) {
|
||||
var str = String(val);
|
||||
|
||||
// percent encode as UTF-8
|
||||
var encoded = encodeURIComponent(str)
|
||||
.replace(ENCODE_URL_ATTR_CHAR_REGEXP, pencode)
|
||||
var encoded = encodeURIComponent(str).replace(
|
||||
ENCODE_URL_ATTR_CHAR_REGEXP,
|
||||
pencode
|
||||
);
|
||||
|
||||
return 'UTF-8\'\'' + encoded
|
||||
return "UTF-8''" + encoded;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -452,7 +451,7 @@ function ustring (val) {
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
function ContentDisposition (type, parameters) {
|
||||
this.type = type
|
||||
this.parameters = parameters
|
||||
function ContentDisposition(type, parameters) {
|
||||
this.type = type;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
Reference in New Issue
Block a user