Code coverage report for lib/body.js

Statements: 100% (21 / 21)      Branches: 100% (12 / 12)      Functions: 100% (6 / 6)      Lines: 100% (21 / 21)      Ignored: 4 branches     

All files » lib/ » body.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 361 1 1 1 1 1 1 5           1 1 1 1 1 1     1 1   4 8 8 8         1      
(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);