"use strict";

exports.__esModule = true;
exports.findInArray = findInArray;
exports.get = get;
exports.getNotUndef = getNotUndef;
exports.getValueFromEvents = getValueFromEvents;
exports.isBoolean = isBoolean;
exports.isFunction = isFunction;
exports.isInvalidValue = isInvalidValue;
exports.isNil = isNil;
exports.isNumber = isNumber;
exports.isString = isString;
exports.isUndef = isUndef;
exports.isValidArray = isValidArray;
exports.nextTick = void 0;
exports.noop = noop;
exports.removeFromArray = removeFromArray;
exports.replaceMessage = replaceMessage;

function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function noop() {}

function get(source, path, defaultValue) {
  var paths = path.replace(/\[(\d+)]/g, '.$1').split('.');
  var result = source;

  for (var _iterator = _createForOfIteratorHelperLoose(paths), _step; !(_step = _iterator()).done;) {
    var p = _step.value;
    result = Object(result)[p];

    if (result === undefined) {
      return defaultValue;
    }
  }

  return result;
}

function isValidArray(obj) {
  return Array.isArray(obj) && obj.length > 0;
}

function findInArray(arr, fn) {
  if (arr === void 0) {
    arr = [];
  }

  var ret = null;

  if (isValidArray(arr)) {
    arr.forEach(function (item, index) {
      if (!ret && fn(item, index)) {
        ret = item;
      }
    });
  }

  return ret;
}

function isString(str) {
  return typeof str === 'string';
}

function isNumber(num) {
  if (num === '' || num === null) {
    return false;
  }

  return typeof num === 'number' && !isNaN(num) || !isNaN(Number(num));
}

function isUndef(obj) {
  return typeof obj === 'undefined';
}

function isFunction(fn) {
  return typeof fn === 'function';
}

function isBoolean(val) {
  return typeof val === 'boolean';
}

function isNil(val) {
  return typeof val === 'undefined' || val === null;
}

function isInvalidValue(val) {
  return isNil(val) || val === '';
}

var nextTick = function (handler) {
  if (typeof requestAnimationFrame !== 'undefined') {
    requestAnimationFrame(handler);
    return;
  }

  if (typeof setTimeout !== 'undefined') {
    setTimeout(handler, 0);
    return;
  }

  handler();
};

exports.nextTick = nextTick;

function removeFromArray(arr, val) {
  if (arr === void 0) {
    arr = [];
  }

  if (val === void 0) {
    val = '';
  }

  return arr.filter(function (v) {
    return v !== val;
  });
}

function replaceMessage(template, kv) {
  return template.replace(/\${\w+}/g, function (str) {
    var key = str.slice(2, -1);
    return kv[key];
  });
}

function getValueFromEvents(e) {
  if (!isUndef(e.value)) {
    return e.value;
  }

  if (get(e, 'target.value')) {
    return e.target.value;
  }

  if (get(e, 'detail.value')) {
    return e.target.value;
  }

  if (get(e, 'originalEvent.detail.value')) {
    return e.originalEvent.detail.value;
  }
}

function getNotUndef() {
  for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
    values[_key] = arguments[_key];
  }

  for (var _i = 0, _values = values; _i < _values.length; _i++) {
    var it = _values[_i];

    if (!isUndef(it)) {
      return it;
    }
  }
}