/** @format */

export function objectCopy<T>(oldObj: T): T {
  return JSON.parse(JSON.stringify(oldObj))
}

/**
 * 判断一个对象是否为空对象
 * @param {obejct} obj 目标对象
 */
export const isEmptyObj = (obj: object) => JSON.stringify(obj) === '{}'
export function getParentsById(list: any, key: string): any {
  for (const i in list) {
    if (list[i].key === key)
      return [list[i]]

    if (list[i].children) {
      const node = getParentsById(list[i].children, key)
      if (node !== undefined)
        return node.concat(list[i])
    }
  }
  return []
}

/**
 * /**
 * 判断一个对象是否为空对象
 */
export function updateURLParameter(key, value) {
  const url = new URL(window.location.href)
  url.searchParams.set(key, value)
  history.pushState({}, '', url)
}
