// biome-ignore lint/suspicious/noExplicitAny: ... because it's a helper file
type AnyVoidFunction = (...arg: any[]) => void
interface DebounceParams {
  callback: AnyVoidFunction
type ThrottleParams = Omit<DebounceParams, 'timerId'>
export const debounce = (params: DebounceParams): AnyVoidFunction => {
  const { callback, timerId = { id: -1 }, delay = 50 } = params
    if (timerId.id !== -1) window.clearTimeout(timerId.id)
    timerId.id = window.setTimeout(() => {
      callback.apply(this, args)
export const throttle = (params: ThrottleParams): AnyVoidFunction => {
  const { callback, delay = 100 } = params
  let throttlePause: boolean
    if (throttlePause === true) return
      callback.apply(this, args)