content-type
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -0,1 +1,6 @@ | ||
1.0.4 / 2017-09-11 | ||
================== | ||
* perf: skip parameter parsing when no parameters | ||
1.0.3 / 2017-09-10 | ||
@@ -2,0 +7,0 @@ ================== |
46
index.js
@@ -129,32 +129,36 @@ /*! | ||
var key | ||
var match | ||
var obj = new ContentType(type.toLowerCase()) | ||
var value | ||
PARAM_REGEXP.lastIndex = index | ||
// parse parameters | ||
if (index !== -1) { | ||
var key | ||
var match | ||
var value | ||
while ((match = PARAM_REGEXP.exec(header))) { | ||
if (match.index !== index) { | ||
throw new TypeError('invalid parameter format') | ||
} | ||
PARAM_REGEXP.lastIndex = index | ||
index += match[0].length | ||
key = match[1].toLowerCase() | ||
value = match[2] | ||
while ((match = PARAM_REGEXP.exec(header))) { | ||
if (match.index !== index) { | ||
throw new TypeError('invalid parameter format') | ||
} | ||
if (value[0] === '"') { | ||
// remove quotes and escapes | ||
value = value | ||
.substr(1, value.length - 2) | ||
.replace(QESC_REGEXP, '$1') | ||
index += match[0].length | ||
key = match[1].toLowerCase() | ||
value = match[2] | ||
if (value[0] === '"') { | ||
// remove quotes and escapes | ||
value = value | ||
.substr(1, value.length - 2) | ||
.replace(QESC_REGEXP, '$1') | ||
} | ||
obj.parameters[key] = value | ||
} | ||
obj.parameters[key] = value | ||
if (index !== header.length) { | ||
throw new TypeError('invalid parameter format') | ||
} | ||
} | ||
if (index !== -1 && index !== header.length) { | ||
throw new TypeError('invalid parameter format') | ||
} | ||
return obj | ||
@@ -161,0 +165,0 @@ } |
{ | ||
"name": "content-type", | ||
"description": "Create and parse HTTP Content-Type header", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
10200
179