forked from request/request
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request request#1039 from seanstrom/support/extract-helper…
…-functions extract out helper functions to a helper file
- Loading branch information
Showing
2 changed files
with
57 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
var extend = require('util')._extend | ||
|
||
function constructObject(initialObject) { | ||
initialObject = initialObject || {} | ||
|
||
return { | ||
extend: function (object) { | ||
return constructObject(extend(initialObject, object)) | ||
}, | ||
done: function () { | ||
return initialObject | ||
} | ||
} | ||
} | ||
|
||
function constructOptionsFrom(uri, options) { | ||
var params = constructObject() | ||
if (typeof uri === 'object') params.extend(uri) | ||
if (typeof uri === 'string') params.extend({uri: uri}) | ||
params.extend(options) | ||
return params.done() | ||
} | ||
|
||
function filterForCallback(values) { | ||
var callbacks = values.filter(isFunction) | ||
return callbacks[0] | ||
} | ||
|
||
function isFunction(value) { | ||
return typeof value === 'function' | ||
} | ||
|
||
function paramsHaveRequestBody(params) { | ||
return ( | ||
params.options.body || | ||
params.options.requestBodyStream || | ||
(params.options.json && typeof params.options.json !== 'boolean') || | ||
params.options.multipart | ||
) | ||
} | ||
|
||
exports.isFunction = isFunction | ||
exports.constructObject = constructObject | ||
exports.constructOptionsFrom = constructOptionsFrom | ||
exports.filterForCallback = filterForCallback | ||
exports.paramsHaveRequestBody = paramsHaveRequestBody |