Skip to content

Commit

Permalink
Refactored mergeParam()
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Feb 4, 2010
1 parent cf31355 commit eb94667
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions lib/express/utils.js
Expand Up @@ -105,7 +105,7 @@ exports.escapeRegexp = function(string, chars) {
/**
* Merge param _key_ and _val_ into _params_. Key
* should be a query string key such as 'user[name]',
* and _val_ is it's associated value. The root _params_
* and _val_ is it's associated object. The root _params_
* object is returned.
*
* @param {string} key
Expand All @@ -118,21 +118,17 @@ exports.mergeParam = function(key, val, params) {
var orig = params,
keys = key.trim().match(/\w+/g),
array = /\[\]$/.test(key)
$(keys).reduce(queryString.parseQuery(key), function(parts, currentKey, i){
$(keys).reduce(queryString.parseQuery(key), function(parts, key, i){
if (i === keys.length - 1)
if (currentKey in params)
if (params[currentKey] instanceof Array)
params[currentKey].push(val)
else
params[currentKey] = [params[currentKey], val]
if (key in params)
params[key] instanceof Array ?
params[key].push(val) :
params[key] = [params[key], val]
else
if (array)
params[currentKey] = [val]
else
params[currentKey] = val
if (!(currentKey in params)) params[currentKey] = {}
params = params[currentKey]
return parts[currentKey]
params[key] = array ? [val] : val
if (!(key in params)) params[key] = {}
params = params[key]
return parts[key]
})
return orig
}

0 comments on commit eb94667

Please sign in to comment.