/**
 * Debounces a function call
 *
 * @param {Function} fn Function to debounce
 * @param {number} ms Milliseconds to wait before calling the function
 * @returns {Function} Debounced function
 */
export const debounce = (fn: Function, ms: number) => {
  let timeout: NodeJS.Timeout;

  return function executor(...args: any[]) {
    const later = () => {
      clearTimeout(timeout);
      fn(...args);
    };

    clearTimeout(timeout);
    timeout = setTimeout(later, ms);
  };
};
