export function isObjEqual (obj1: Record<string, string | number | boolean>, obj2: Record<string, string | number | boolean>): boolean {
  const filteredObj1 = filterIgnored(obj1)
  const filteredObj2 = filterIgnored(obj2)

  const allKeys = new Set([...Object.keys(filteredObj1), ...Object.keys(filteredObj2)])

  for (const key of allKeys) {
      const hasKey1 = Object.prototype.hasOwnProperty.call(filteredObj1, key)
      const hasKey2 = Object.prototype.hasOwnProperty.call(filteredObj2, key)
      
      if (hasKey1 !== hasKey2) return false
      if (hasKey1 && hasKey2 && filteredObj1[key] !== filteredObj2[key]) return false
  }

  return true
}

function filterIgnored(obj: Record<string, string | number | boolean>): Record<string, string | number | boolean> {
  const filtered: Record<string, string | number | boolean> = {}

  for (const key in obj) {
      const value = obj[key]
      if (value !== "" && value !== 0 && value !== false) filtered[key] = value
  }

  return filtered
}

export function parseIntString (s: string | string[] | undefined) :number | null {
  if (typeof s !== 'string') return null
  const regex = /^[+-]?\d+$/
  return regex.test(s) ? Number(s) : null 
}