Skip to content

Commit

Permalink
perf: use a class for object creation
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Mar 25, 2017
1 parent 4ee2df9 commit e5201db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ unreleased

* Remove `parse(req)` and `parse(res)` signatures
- Use the `content-type` module for content type parsing
* perf: use a class for object creation

0.3.0 / 2014-09-07
==================
Expand Down
23 changes: 13 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ function parse (string) {
var key
var match
var obj = splitType(type)
var params = {}
var value

PARAM_REGEXP.lastIndex = index
Expand All @@ -174,15 +173,13 @@ function parse (string) {
.replace(QESC_REGEXP, '$1')
}

params[key] = value
obj.parameters[key] = value
}

if (index !== -1 && index !== string.length) {
throw new TypeError('invalid parameter format')
}

obj.parameters = params

return obj
}

Expand Down Expand Up @@ -235,11 +232,17 @@ function splitType (string) {
subtype = subtype.substr(0, index)
}

var obj = {
type: type,
subtype: subtype,
suffix: suffix
}
return new MediaType(type, subtype, suffix)
}

return obj
/**
* Class for MediaType object.
* @public
*/

function MediaType (type, subtype, suffix) {
this.type = type
this.subtype = subtype
this.suffix = suffix
this.parameters = Object.create(null)
}

0 comments on commit e5201db

Please sign in to comment.