Code coverage report for lib/result.js

Statements: 100% (45 / 45)      Branches: 94.44% (17 / 18)      Functions: 100% (14 / 14)      Lines: 100% (42 / 42)      Ignored: 4 branches     

All files » lib/ » result.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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 641 1 1 1 1 1 1 1 1 13 13 13 13 13 13 1 1 10         1 2   1 1   1 2   1 1 1       1 1 1   1     1 1   6 15 15 15         1   1 1 1 1      
(function(){
  var STATUS_CODES, from, Promise, Result;
  STATUS_CODES = require('http').STATUS_CODES;
  from = require('from');
  Promise = require('fantasy-promises');
  module.exports = Result = (function(){
    Result.displayName = 'Result';
    var prototype = Result.prototype, constructor = Result;
    function Result(body, statusCode, status, headers){
      var this$ = this instanceof ctor$ ? this : new ctor$;
      this$.body = body;
      this$.statusCode = statusCode;
      this$.status = status;
      this$.headers = headers;
      return this$;
    } function ctor$(){} ctor$.prototype = prototype;
    Result.simple = curry$(function(code, body){
      return Result(from([body]), code, STATUS_CODES[code], {
        'content-length': body.length,
        'content-type': 'text/plain'
      });
    });
    Result.ok = function(){
      return Promise.of(this.simple(200).apply(this, arguments));
    };
    Result.notFound = function(){
      return Promise.of(this.simple(404).apply(this, arguments));
    };
    Result.error = function(){
      return Promise.of(this.simple(500).apply(this, arguments));
    };
    Result.redirect = function(url, code){
      code == null && (code = 302);
      return Promise.of(Result(from([]), code, null, {
        location: url
      }));
    };
    prototype.withHeaders = function(more){
      import$(this.headers, more);
      return this;
    };
    return Result;
  }());
  /* 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();
  }
  function import$(obj, src){
    var own = {}.hasOwnProperty;
    for (var key in src) Eif (own.call(src, key)) obj[key] = src[key];
    return obj;
  }
}).call(this);