content-type 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/HISTORY.md +5 -0
  2. package/index.js +25 -21
  3. package/package.json +1 -1
package/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ 1.0.4 / 2017-09-11
2
+ ==================
3
+
4
+ * perf: skip parameter parsing when no parameters
5
+
1
6
  1.0.3 / 2017-09-10
2
7
  ==================
3
8
 
package/index.js CHANGED
@@ -126,34 +126,38 @@ function parse (string) {
126
126
  throw new TypeError('invalid media type')
127
127
  }
128
128
 
129
- var key
130
- var match
131
129
  var obj = new ContentType(type.toLowerCase())
132
- var value
133
130
 
134
- PARAM_REGEXP.lastIndex = index
131
+ // parse parameters
132
+ if (index !== -1) {
133
+ var key
134
+ var match
135
+ var value
135
136
 
136
- while ((match = PARAM_REGEXP.exec(header))) {
137
- if (match.index !== index) {
138
- throw new TypeError('invalid parameter format')
139
- }
137
+ PARAM_REGEXP.lastIndex = index
140
138
 
141
- index += match[0].length
142
- key = match[1].toLowerCase()
143
- value = match[2]
139
+ while ((match = PARAM_REGEXP.exec(header))) {
140
+ if (match.index !== index) {
141
+ throw new TypeError('invalid parameter format')
142
+ }
144
143
 
145
- if (value[0] === '"') {
146
- // remove quotes and escapes
147
- value = value
148
- .substr(1, value.length - 2)
149
- .replace(QESC_REGEXP, '$1')
150
- }
144
+ index += match[0].length
145
+ key = match[1].toLowerCase()
146
+ value = match[2]
151
147
 
152
- obj.parameters[key] = value
153
- }
148
+ if (value[0] === '"') {
149
+ // remove quotes and escapes
150
+ value = value
151
+ .substr(1, value.length - 2)
152
+ .replace(QESC_REGEXP, '$1')
153
+ }
154
+
155
+ obj.parameters[key] = value
156
+ }
154
157
 
155
- if (index !== -1 && index !== header.length) {
156
- throw new TypeError('invalid parameter format')
158
+ if (index !== header.length) {
159
+ throw new TypeError('invalid parameter format')
160
+ }
157
161
  }
158
162
 
159
163
  return obj
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "content-type",
3
3
  "description": "Create and parse HTTP Content-Type header",
4
- "version": "1.0.3",
4
+ "version": "1.0.4",
5
5
  "author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
6
6
  "license": "MIT",
7
7
  "keywords": [