const opt = Object.prototype.toString;
function isUndefined(val) {
  return val === void 0;
}
function isNull(val) {
  return opt.call(val) === "[object Null]";
}
function isBoolean(val) {
  return opt.call(val) === "[object Boolean]";
}
function isString(val) {
  return opt.call(val) === "[object String]";
}
function isNumber(val) {
  return opt.call(val) === "[object Number]" && !Number.isNaN(val);
}
function isFunction(val) {
  return typeof val === "function";
}
function isArray(val) {
  return Array.isArray(val);
}
function isEmptyArray(val) {
  return isArray(val) && val.length === 0;
}
function isArrayEqual(arr1, arr2) {
  if (!isArray(arr1) || !isArray(arr2)) {
    return false;
  }
  const len = arr1.length;
  if (len !== arr2.length) {
    return false;
  }
  for (let i = 0; i < len; i++) {
    if (!arr2.includes(arr1[i])) {
      return false;
    }
  }
  return true;
}
function isEmptyObject(val) {
  return opt.call(val) === "[object object]" && Object.keys(val).length === 0;
}
function isValidDate(val) {
  return val instanceof Date && !Number.isNaN(val.valueOf());
}
function isObject(val) {
  return val !== null && typeof val === "object";
}
function isPlainObject(val) {
  return opt.call(val) === "[object Object]";
}
const isPromise = (val) => {
  return isObject(val) && isFunction(val.then) && isFunction(val.catch);
};
const isClient = typeof window !== "undefined";
const isTouchDevice = isClient ? "ontouchstart" in document.documentElement : false;
function isWindow(val) {
  return val === window;
}
function isCurrentPageLink(link) {
  if (link.startsWith("#")) {
    return true;
  }
  try {
    const targetUrl = new URL(link, window.location.href);
    return targetUrl.origin + targetUrl.pathname === window.location.origin + window.location.pathname;
  } catch {
    return false;
  }
}
export {
  isArray,
  isArrayEqual,
  isBoolean,
  isClient,
  isCurrentPageLink,
  isEmptyArray,
  isEmptyObject,
  isFunction,
  isNull,
  isNumber,
  isObject,
  isPlainObject,
  isPromise,
  isString,
  isTouchDevice,
  isUndefined,
  isValidDate,
  isWindow
};
