All files / predicate/lib chain.js

100% Statements 24/24
100% Branches 2/2
100% Functions 11/11
100% Lines 23/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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    1x         13x       1x       15x           5x 5x           8x 8x         1x 2x 106x 2x       104x 22x 22x     104x       1x   1x 5x   1x   1x 8x   1x  
'use strict';
 
const predicates = require('./predicates');
 
// chaining mixin
class Lazy {
  constructor() {
    this.lazy = [];
  }
 
  valueOf() {
    return this.val();
  }
 
  val() {
    return this.lazy[this.method](args => args[0].apply(null, args[1]));
  }
}
 
class Every extends Lazy {
  constructor() {
    super();
    this.method = 'every';
  }
}
 
class Some extends Lazy {
  constructor() {
    super();
    this.method = 'some';
  }
}
 
// Extend chaining methods onto the prototypes
[Every, Some].forEach(cls => {
  Object.keys(predicates).reduce((proto, fnName) => {
    if (!predicates.fn(predicates[fnName])) {
      return proto;
    }
 
    /* eslint-disable-next-line func-names, no-param-reassign */
    proto[fnName] = function() {
      this.lazy.push([predicates[fnName], arguments]);
      return this;
    };
 
    return proto;
  }, cls.prototype);
});
 
const predicate = module.exports;
 
predicate.every = function every() {
  return new Every();
};
predicate.all = predicate.every;
 
predicate.some = function some() {
  return new Some();
};
predicate.any = predicate.some;