Code coverage report for lib/respond.js

Statements: 100% (26 / 26)      Branches: 100% (14 / 14)      Functions: 100% (9 / 9)      Lines: 100% (26 / 26)      Ignored: 5 branches     

All files » lib/ » respond.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 36 37 38 39 40 41 42 431 1 1 1 1 3 2   1     1 3 3 3 3 3 2 1         1 9 9     1 1   10 12 12 12         1      
(function(){
  var compilePath, σ, guard, respond, i$, ref$, len$, m;
  compilePath = require('./compiler').compilePath;
  σ = require('highland');
  guard = function(cond){
    if (cond) {
      return σ([null]);
    } else {
      return σ([]);
    }
  };
  module.exports = respond = curry$(function(method, path, responder){
    var lower, extract;
    lower = method.toLowerCase();
    extract = compilePath(path);
    return function(request){
      return guard(lower === request.method.toLowerCase()).flatMap(function(){
        return extract(request.url).flatMap(function(params){
          return responder((request.params = params, request.route = path, request));
        });
      });
    };
  });
  for (i$ = 0, len$ = (ref$ = ['get', 'post', 'put', 'delete', 'patch', 'options', 'head', 'trace', 'connect']).length; i$ < len$; ++i$) {
    m = ref$[i$];
    module.exports[m] = respond(m);
  }
  /* 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);