All files utils.js

89.83% Statements 53/59
89.65% Branches 26/29
66.66% Functions 8/12
92.72% Lines 51/55

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                                                    40x 334x 334x   334x 128x 42x 42x   86x   206x 5x 5x   248x 243x 452x 452x 16x   436x       248x   40x                               40x 2x   40x 16x   40x 14x 2x 5x     12x 4x 4x 7x 7x     4x   8x         40x   84x     84x 1248x           40x 452x 452x     17x 17x 1x 1x 1x 1x 1x 1x 1x       452x  
'use strict';
 
/*
Gets a property's value.
 
:keys = An array of keys to search for
:pointers = An object with keys that point to a specific variable / object
 
First search in pointers if pointers is defined. Then search in methods and lastly
search in the component itself. Go deeper, one key at a time until we reach the last
one or until we get an undefined value.
*/
import "core-js/modules/es.symbol.js";
import "core-js/modules/es.symbol.description.js";
import "core-js/modules/es.symbol.iterator.js";
import "core-js/modules/es.array.is-array.js";
import "core-js/modules/es.array.iterator.js";
import "core-js/modules/es.array.map.js";
import "core-js/modules/es.array.some.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/es.regexp.exec.js";
import "core-js/modules/es.string.iterator.js";
import "core-js/modules/es.string.match.js";
import "core-js/modules/web.dom-collections.iterator.js";
/* istanbul ignore next */
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
export var getProp = function getProp(comp, keys, pointers) {
  var firstKey = keys[0];
  var root = comp;
  var prop;
  if (pointers && firstKey in pointers) {
    if (keys.length > 1) {
      keys.shift();
      root = pointers[firstKey];
    } else {
      return pointers[firstKey];
    }
  } else if (firstKey in comp.methods) {
    keys.shift();
    prop = comp.methods[firstKey](comp);
  }
  if (keys.length > 0) {
    for (var i = 0; i < keys.length; i++) {
      prop = getObjectFromKey(root, keys[i]);
      if (prop === undefined) {
        break;
      } else {
        root = prop;
      }
    }
  }
  return prop;
};
export var helpers = {
  getNode: function getNode(selectors) {
    return this.comp.el.querySelector(selectors);
  },
  getNodes: function getNodes(selectors) {
    return this.comp.el.querySelectorAll(selectors);
  },
  appendIn: function appendIn(HTML, node) {
    return node.innerHTML += HTML;
  },
  prependIn: function prependIn(HTML, node) {
    return node.innerHTML = HTML + node.innerHTML;
  }
};
 
// Small, commonly-used helpers for object inspection and manipulation
export var hasOwn = function hasOwn(obj, key) {
  return Object.prototype.hasOwnProperty.call(obj, key);
};
export var isObject = function isObject(value) {
  return value !== null && _typeof(value) === 'object' && !Array.isArray(value);
};
var _deepClone = function deepClone(value) {
  if (Array.isArray(value)) {
    return value.map(function (v) {
      return _deepClone(v);
    });
  }
  if (isObject(value)) {
    var out = {};
    for (var k in value) {
      Eif (Object.prototype.hasOwnProperty.call(value, k)) {
        out[k] = _deepClone(value[k]);
      }
    }
    return out;
  }
  return value;
};
 
// Expression safety utilities for c-if / c-ifnot directives
export { _deepClone as deepClone };
export var isBlockedExpression = function isBlockedExpression(expr) {
  // Block dangerous tokens and constructs
  var blockedPatterns = [/\bconstructor\b/, /\b__proto__\b/, /\beval\b/, /\bFunction\b/, /(?<![=!<>])=(?![=])/,
  // assignment not part of == === != !==
  /\+\+|--/, /\bnew\b/, /\bfunction\b/, /\bclass\b/, /=>/, /\bimport\b/, /\bawait\b/, /\byield\b/, /\btry\b|\bcatch\b|\bfinally\b/, /\bdelete\b/];
  return blockedPatterns.some(function (pattern) {
    return pattern.test(expr);
  });
};
 
// Private functions ===================================================================================================
// Try to get the value of an object.
var getObjectFromKey = function getObjectFromKey(root, key) {
  var prop = root[key];
  if (prop === undefined) {
    // If there is no value then check if the key uses the square brackets notation (ie: obj[key]) and try to retrieve
    // a value this way.
    var dKeys = key.match(/\[(.*?)\]/g);
    if (dKeys) {
      var dObjName = key.split('[')[0];
      var dRoot = root[dObjName];
      for (var i = 0; i < dKeys.length; i++) {
        Iif (i > 0) dRoot = prop;
        var cleanedKey = dKeys[i].split('[')[1].split(']')[0];
        prop = dRoot[cleanedKey];
        Iif (prop === undefined) break;
      }
    }
  }
  return prop;
};