debounce = (fn, delay, { leading = false } = {}) => {
  isFunction(fn) && isNumber(delay)
  /**
   * @type {NodeJS.Timeout}
   */
  let timerId

  return (...args) => {
    if (!timerId && leading) {
      fn(...args)
    }
    clearTimeout(timerId)

    timerId = setTimeout(() => fn(...args), delay)
  }
}
@see https://youmightnotneed.com/lodash#debounce

@template A
@template R
@param {(...args: A[]) => R} fn - The function to debounce.
@param {number} delay - The number of milliseconds to delay.
@param {Object} options
@param {boolean} [options.leading]
@returns {(...args: A[]) => void}