All files index.js

91.53% Statements 108/118
76.77% Branches 76/99
89.29% Functions 25/28
100% Lines 81/81

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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161    1x     1x   1x   1x   1x   3x   12x   5x   1x   2x   3x   8x   52x     12x   12x 1x 11x 1x 10x 4x 2x   2x 1x 1x 1x 1x 3x   1x 3x         6x         26x   26x 1x 25x 4x 6x   21x 2x   19x         12x 3x   9x         12x 2x 10x 2x 8x 5x   3x         12x   12x 3x 9x 2x 7x 2x   5x       1x   12x   12x   12x 12x     12x 12x 12x 12x 12x     1x     12x 12x         12x 12x         12x 12x         12x 12x         12x 12x 12x       1x     1x
"use strict";
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
 
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
 
var _hash = _interopRequireDefault(require("hash.js"));
 
var _baseconvert = _interopRequireDefault(require("baseconvert"));
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
 
function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; Eif ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
 
function _createClass(Constructor, protoProps, staticProps) { Eif (protoProps) _defineProperties(Constructor.prototype, protoProps); Iif (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
 
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); Eif (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); Eif (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
 
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; Eif (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
 
function _defineProperty(obj, key, value) { Iif (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
 
function _typeof(obj) { "@babel/helpers - typeof"; Eif (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
 
function castString(input) {
  var isArray = Array.isArray(input);
 
  if (!input && typeof input === 'boolean') {
    return 'false';
  } else if (input === 0) {
    return '0';
  } else if (input && _typeof(input) === 'object') {
    if ((0, _isEmpty["default"])(input)) {
      return '';
    } else {
      if (isArray) {
        return "[".concat(input.join(', '), "]");
      } else Eif (!isArray) {
        var values = Object.values(input);
        var entries = Object.keys(input).map(function (k, i) {
          return [k, values[i]];
        });
        return "{".concat(entries.map(function (entry) {
          return entry.join(': ');
        }).join(', '), "}");
      }
    }
  } else {
    return input ? '' + input : '';
  }
}
 
function castNumber(input) {
  var isArray = Array.isArray(input);
 
  if (typeof input === 'string' && input) {
    return _baseconvert["default"].hex2dec(_hash["default"].sha1().update(input).digest('hex'));
  } else if (isArray) {
    return input.reduce(function (a, b) {
      return castNumber(a) + castNumber(b);
    }, 0);
  } else if (input && _typeof(input) === 'object' && !isArray) {
    return castNumber(Object.values(input));
  } else {
    return input ? +input : 0;
  }
}
 
function castBoolean(input) {
  if (_typeof(input) === 'object' && (0, _isEmpty["default"])(input)) {
    return false;
  } else {
    return !!input;
  }
}
 
function castArray(input) {
  if (Array.isArray(input)) {
    return input;
  } else if (_typeof(input) === 'object' && input) {
    return Object.values(input);
  } else if (input || typeof input === 'boolean' || input === 0) {
    return [input];
  } else {
    return [];
  }
}
 
function castObject(input, defaultKey) {
  var isArray = Array.isArray(input);
 
  if (!(input || typeof input === 'boolean' || input === 0)) {
    return {};
  } else if (_typeof(input) === 'object' && !isArray) {
    return input;
  } else if (isArray) {
    return _objectSpread({}, input);
  } else {
    return _defineProperty({}, defaultKey, input);
  }
}
 
var TypeInsurance = /*#__PURE__*/function () {
  function TypeInsurance(input) {
    var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
 
    _classCallCheck(this, TypeInsurance);
 
    this.input = input;
    this.defaultKey = options.hasOwnProperty('defaultKey') ? castString(options.defaultKey, {
      hash: true
    }) : 'key';
    this.string = this._string();
    this.number = this._number();
    this["boolean"] = this._boolean();
    this.array = this._array();
    this.object = this._object();
  }
 
  _createClass(TypeInsurance, [{
    key: "_string",
    value: function _string() {
      var input = this.input;
      return castString(input);
    }
  }, {
    key: "_number",
    value: function _number() {
      var input = this.input;
      return castNumber(input);
    }
  }, {
    key: "_boolean",
    value: function _boolean() {
      var input = this.input;
      return castBoolean(input);
    }
  }, {
    key: "_array",
    value: function _array() {
      var input = this.input;
      return castArray(input);
    }
  }, {
    key: "_object",
    value: function _object() {
      var input = this.input,
          defaultKey = this.defaultKey;
      return castObject(input, defaultKey);
    }
  }]);
 
  return TypeInsurance;
}();
 
exports["default"] = TypeInsurance;