(function(){
var σ, getBody, handleException, qs;
σ = require('highland');
getBody = σ.wrapCallback(require('raw-body'));
handleException = require('./error').handleException;
qs = require('qs');
exports.bodyParams = curry$(function(parser, req){
return getBody(req, {
length: req.headers['content-length'],
encoding: 'utf8',
limit: '1mb'
}).flatMap(parser);
});
exports.jsonParse = handleException(JSON.parse);
exports.queryParse = handleException(qs.parse);
exports.json = exports.bodyParams(exports.jsonParse);
exports.query = exports.bodyParams(exports.queryParse);
exports.raw = exports.bodyParams(function(it){
return σ([it]);
});
/* istanbul ignore next */
function curry$(f, bound){
var context,
_curry = function(args) {
return f.length > 1 ? function(){
var params = args ? args.concat() : [];
context = bound ? context || this : this;
return params.push.apply(params, arguments) <
f.length && arguments.length ?
_curry.call(context, params) : f.apply(context, params);
} : f;
};
return _curry();
}
}).call(this);
|