all files / lib/ util.js

100% Statements 26/26
100% Branches 14/14
100% Functions 7/7
100% Lines 26/26
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    1299×   1298×     1290×     2682× 33× 33×       1086× 411×   1086×                                      
"use strict";
 
function isType(ref, type) {
  if (type === 'array') {
    return Array.isArray(ref);
  }
  if (type === 'promise') {
    return typeof ref.then === 'function' &&
        typeof ref.catch === 'function';
  }
  return typeof ref === type;
}
module.exports.isType = isType;
 
function assert(condition, message, ErrorType) {
  if (!condition) {
    var E = ErrorType || Error;
    throw new E(message);
  }
}
 
assert.type = function(ref, type, message, ErrorType) {
  var pass = Array.isArray(type)
    ? type.some(function(t) { return isType(ref, t); })
    : isType(ref, type);
  assert(pass, message, ErrorType);
};
 
module.exports.assert = assert;
 
// "inherits" function: shamelessly lifted from browserified util shim for the sake of
// not including the entire util module
if (typeof Object.create === 'function') {
  // implementation from standard node.js 'util' module
  module.exports.inherits = function(ctor, superCtor) {
    ctor.super_ = superCtor;
    ctor.prototype = Object.create(superCtor.prototype, {
      constructor: {
        value: ctor,
        enumerable: false,
        writable: true,
        configurable: true
      }
    });
  };
} else {
  // old school shim for old browsers
  module.exports.inherits = function(ctor, superCtor) {
    ctor.super_ = superCtor;
    var TempCtor = function () {};
    TempCtor.prototype = superCtor.prototype;
    ctor.prototype = new TempCtor();
    ctor.prototype.constructor = ctor;
  };
}