"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
var _ObjectUtils;
class ObjectUtils {
  static getDataType(data) {
    let type = typeof data;
    if (type !== 'object') {
      return type;
    }
    return Object.prototype.toString.call(data).replace(/^\[object (\S+)\]$/, '$1');
  }
  static iterable(data) {
    return ['Object', 'Array'].includes(this.getDataType(data));
  }
  static isObjectChanged(source, comparison, notIncludeKeys) {
    if (!this.iterable(source)) {
      throw new Error("source should be a Object or Array , but got ".concat(this.getDataType(source)));
    }
    if (this.getDataType(source) !== this.getDataType(comparison)) {
      return true;
    }
    const sourceKeys = Object.keys(source);
    const comparisonKeys = Object.keys((0, _objectSpread2.default)((0, _objectSpread2.default)({}, source), comparison)).filter(key => !notIncludeKeys.includes(key));
    if (sourceKeys.length !== comparisonKeys.length) {
      return true;
    }
    return comparisonKeys.some(key => {
      if (this.iterable(source[key])) {
        return this.isObjectChanged(source[key], comparison[key], notIncludeKeys);
      } else {
        return source[key] !== comparison[key];
      }
    });
  }
  static isSameObject(source, comparison) {
    let notIncludeKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
    if (!source || !comparison) return false;
    return !this.isObjectChanged(source, comparison, notIncludeKeys);
  }
}
_ObjectUtils = ObjectUtils;
(0, _defineProperty2.default)(ObjectUtils, "isObject", data => {
  return _ObjectUtils.getDataType(data) === 'Object';
});
(0, _defineProperty2.default)(ObjectUtils, "hasProperty", (obj, prop) => {
  if (!obj) return false;
  return Object.prototype.hasOwnProperty.call(obj, prop);
});
var _default = exports.default = ObjectUtils;